Changeset 0.29.2 (#197)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
20
server/store/ext_data_iface.go
Normal file
20
server/store/ext_data_iface.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package store
|
||||
|
||||
import "context"
|
||||
|
||||
// ExtDataStore tracks the namespaced tables created for each extension.
|
||||
// It is the catalog backing db.list_tables() and the install/uninstall lifecycle.
|
||||
// The actual extension data lives in tables named ext_{package_id}_{table_name};
|
||||
// this store only records the logical (unprefixed) names.
|
||||
type ExtDataStore interface {
|
||||
// RegisterTable records that a table was created for a package.
|
||||
// Safe to call multiple times — idempotent.
|
||||
RegisterTable(ctx context.Context, packageID, tableName string) error
|
||||
|
||||
// ListTables returns all logical table names registered for a package.
|
||||
ListTables(ctx context.Context, packageID string) ([]string, error)
|
||||
|
||||
// DeletePackageTables removes all catalog entries for a package.
|
||||
// Called after the physical tables have been dropped on uninstall.
|
||||
DeletePackageTables(ctx context.Context, packageID string) error
|
||||
}
|
||||
@@ -61,6 +61,7 @@ type Stores struct {
|
||||
Folders FolderStore // v0.29.0: Chat folder CRUD
|
||||
Health HealthStore // v0.29.0: Provider health window management
|
||||
ExtPermissions ExtensionPermissionStore // v0.29.0: Extension declared/granted capabilities
|
||||
ExtData ExtDataStore // v0.29.2: Extension namespaced table catalog
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
55
server/store/postgres/ext_data.go
Normal file
55
server/store/postgres/ext_data.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// ExtDataStore implements store.ExtDataStore for Postgres.
|
||||
type ExtDataStore struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewExtDataStore(db *sql.DB) *ExtDataStore {
|
||||
return &ExtDataStore{db: db}
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) RegisterTable(ctx context.Context, packageID, tableName string) error {
|
||||
_, err := s.db.ExecContext(ctx,
|
||||
`INSERT INTO ext_data_tables (package_id, table_name)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (package_id, table_name) DO NOTHING`,
|
||||
packageID, tableName)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) ListTables(ctx context.Context, packageID string) ([]string, error) {
|
||||
rows, err := s.db.QueryContext(ctx,
|
||||
`SELECT table_name FROM ext_data_tables
|
||||
WHERE package_id = $1
|
||||
ORDER BY table_name`,
|
||||
packageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var names []string
|
||||
for rows.Next() {
|
||||
var n string
|
||||
if err := rows.Scan(&n); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
names = append(names, n)
|
||||
}
|
||||
if names == nil {
|
||||
names = []string{}
|
||||
}
|
||||
return names, nil
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) DeletePackageTables(ctx context.Context, packageID string) error {
|
||||
_, err := s.db.ExecContext(ctx,
|
||||
`DELETE FROM ext_data_tables WHERE package_id = $1`, packageID)
|
||||
return err
|
||||
}
|
||||
@@ -47,5 +47,6 @@ func NewStores(db *sql.DB) store.Stores {
|
||||
Folders: NewFolderStore(),
|
||||
Health: NewHealthStore(db),
|
||||
ExtPermissions: NewExtensionPermissionStore(db),
|
||||
ExtData: NewExtDataStore(db),
|
||||
}
|
||||
}
|
||||
|
||||
49
server/store/sqlite/ext_data.go
Normal file
49
server/store/sqlite/ext_data.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package sqlite
|
||||
|
||||
import "context"
|
||||
|
||||
// ExtDataStore implements store.ExtDataStore for SQLite.
|
||||
type ExtDataStore struct{}
|
||||
|
||||
func NewExtDataStore() *ExtDataStore {
|
||||
return &ExtDataStore{}
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) RegisterTable(ctx context.Context, packageID, tableName string) error {
|
||||
_, err := DB.ExecContext(ctx,
|
||||
`INSERT OR IGNORE INTO ext_data_tables (package_id, table_name)
|
||||
VALUES (?, ?)`,
|
||||
packageID, tableName)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) ListTables(ctx context.Context, packageID string) ([]string, error) {
|
||||
rows, err := DB.QueryContext(ctx,
|
||||
`SELECT table_name FROM ext_data_tables
|
||||
WHERE package_id = ?
|
||||
ORDER BY table_name`,
|
||||
packageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var names []string
|
||||
for rows.Next() {
|
||||
var n string
|
||||
if err := rows.Scan(&n); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
names = append(names, n)
|
||||
}
|
||||
if names == nil {
|
||||
names = []string{}
|
||||
}
|
||||
return names, nil
|
||||
}
|
||||
|
||||
func (s *ExtDataStore) DeletePackageTables(ctx context.Context, packageID string) error {
|
||||
_, err := DB.ExecContext(ctx,
|
||||
`DELETE FROM ext_data_tables WHERE package_id = ?`, packageID)
|
||||
return err
|
||||
}
|
||||
@@ -47,5 +47,6 @@ func NewStores(db *sql.DB) store.Stores {
|
||||
Folders: NewFolderStore(),
|
||||
Health: NewHealthStore(),
|
||||
ExtPermissions: NewExtensionPermissionStore(),
|
||||
ExtData: NewExtDataStore(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user