@elizaos/plugin-sql 1.6.5-alpha.13 → 1.6.5-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/browser/base.d.ts +0 -965
- package/dist/browser/index.browser.d.ts +0 -11
- package/dist/browser/migration-service.d.ts +0 -43
- package/dist/browser/migrations.d.ts +0 -15
- package/dist/browser/pglite/adapter.d.ts +0 -76
- package/dist/browser/pglite/manager.d.ts +0 -21
- package/dist/browser/rls.d.ts +0 -156
- package/dist/browser/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
- package/dist/browser/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
- package/dist/browser/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
- package/dist/browser/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
- package/dist/browser/runtime-migrator/extension-manager.d.ts +0 -6
- package/dist/browser/runtime-migrator/index.d.ts +0 -8
- package/dist/browser/runtime-migrator/runtime-migrator.d.ts +0 -96
- package/dist/browser/runtime-migrator/schema-transformer.d.ts +0 -16
- package/dist/browser/runtime-migrator/storage/journal-storage.d.ts +0 -10
- package/dist/browser/runtime-migrator/storage/migration-tracker.d.ts +0 -13
- package/dist/browser/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
- package/dist/browser/runtime-migrator/types.d.ts +0 -48
- package/dist/browser/schema/agent.d.ts +0 -344
- package/dist/browser/schema/cache.d.ts +0 -97
- package/dist/browser/schema/channel.d.ts +0 -177
- package/dist/browser/schema/channelParticipant.d.ts +0 -41
- package/dist/browser/schema/component.d.ts +0 -163
- package/dist/browser/schema/embedding.d.ts +0 -193
- package/dist/browser/schema/entity.d.ts +0 -122
- package/dist/browser/schema/index.d.ts +0 -18
- package/dist/browser/schema/log.d.ts +0 -114
- package/dist/browser/schema/memory.d.ts +0 -188
- package/dist/browser/schema/message.d.ts +0 -1
- package/dist/browser/schema/messageServer.d.ts +0 -126
- package/dist/browser/schema/messageServerAgent.d.ts +0 -41
- package/dist/browser/schema/participant.d.ts +0 -114
- package/dist/browser/schema/relationship.d.ts +0 -156
- package/dist/browser/schema/room.d.ts +0 -192
- package/dist/browser/schema/server.d.ts +0 -64
- package/dist/browser/schema/tasks.d.ts +0 -225
- package/dist/browser/schema/types.d.ts +0 -68
- package/dist/browser/schema/world.d.ts +0 -114
- package/dist/browser/src/base.d.ts +0 -965
- package/dist/browser/src/index.browser.d.ts +0 -11
- package/dist/browser/src/migration-service.d.ts +0 -43
- package/dist/browser/src/migrations.d.ts +0 -15
- package/dist/browser/src/pglite/adapter.d.ts +0 -76
- package/dist/browser/src/pglite/manager.d.ts +0 -21
- package/dist/browser/src/rls.d.ts +0 -156
- package/dist/browser/src/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
- package/dist/browser/src/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
- package/dist/browser/src/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
- package/dist/browser/src/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
- package/dist/browser/src/runtime-migrator/extension-manager.d.ts +0 -6
- package/dist/browser/src/runtime-migrator/index.d.ts +0 -8
- package/dist/browser/src/runtime-migrator/runtime-migrator.d.ts +0 -96
- package/dist/browser/src/runtime-migrator/schema-transformer.d.ts +0 -16
- package/dist/browser/src/runtime-migrator/storage/journal-storage.d.ts +0 -10
- package/dist/browser/src/runtime-migrator/storage/migration-tracker.d.ts +0 -13
- package/dist/browser/src/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
- package/dist/browser/src/runtime-migrator/types.d.ts +0 -48
- package/dist/browser/src/schema/agent.d.ts +0 -344
- package/dist/browser/src/schema/cache.d.ts +0 -97
- package/dist/browser/src/schema/channel.d.ts +0 -177
- package/dist/browser/src/schema/channelParticipant.d.ts +0 -41
- package/dist/browser/src/schema/component.d.ts +0 -163
- package/dist/browser/src/schema/embedding.d.ts +0 -193
- package/dist/browser/src/schema/entity.d.ts +0 -122
- package/dist/browser/src/schema/index.d.ts +0 -18
- package/dist/browser/src/schema/log.d.ts +0 -114
- package/dist/browser/src/schema/memory.d.ts +0 -188
- package/dist/browser/src/schema/message.d.ts +0 -1
- package/dist/browser/src/schema/messageServer.d.ts +0 -126
- package/dist/browser/src/schema/messageServerAgent.d.ts +0 -41
- package/dist/browser/src/schema/participant.d.ts +0 -114
- package/dist/browser/src/schema/relationship.d.ts +0 -156
- package/dist/browser/src/schema/room.d.ts +0 -192
- package/dist/browser/src/schema/server.d.ts +0 -64
- package/dist/browser/src/schema/tasks.d.ts +0 -225
- package/dist/browser/src/schema/types.d.ts +0 -68
- package/dist/browser/src/schema/world.d.ts +0 -114
- package/dist/browser/src/types.d.ts +0 -15
- package/dist/browser/src/utils.browser.d.ts +0 -21
- package/dist/browser/types.d.ts +0 -15
- package/dist/browser/utils.browser.d.ts +0 -21
- package/dist/node/src/base.d.ts +0 -965
- package/dist/node/src/index.d.ts +0 -33
- package/dist/node/src/index.node.d.ts +0 -10
- package/dist/node/src/migration-service.d.ts +0 -43
- package/dist/node/src/migrations.d.ts +0 -15
- package/dist/node/src/pg/adapter.d.ts +0 -78
- package/dist/node/src/pg/manager.d.ts +0 -33
- package/dist/node/src/pglite/adapter.d.ts +0 -76
- package/dist/node/src/pglite/manager.d.ts +0 -21
- package/dist/node/src/rls.d.ts +0 -156
- package/dist/node/src/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
- package/dist/node/src/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
- package/dist/node/src/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
- package/dist/node/src/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
- package/dist/node/src/runtime-migrator/extension-manager.d.ts +0 -6
- package/dist/node/src/runtime-migrator/index.d.ts +0 -8
- package/dist/node/src/runtime-migrator/runtime-migrator.d.ts +0 -96
- package/dist/node/src/runtime-migrator/schema-transformer.d.ts +0 -16
- package/dist/node/src/runtime-migrator/storage/journal-storage.d.ts +0 -10
- package/dist/node/src/runtime-migrator/storage/migration-tracker.d.ts +0 -13
- package/dist/node/src/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
- package/dist/node/src/runtime-migrator/types.d.ts +0 -48
- package/dist/node/src/schema/agent.d.ts +0 -344
- package/dist/node/src/schema/cache.d.ts +0 -97
- package/dist/node/src/schema/channel.d.ts +0 -177
- package/dist/node/src/schema/channelParticipant.d.ts +0 -41
- package/dist/node/src/schema/component.d.ts +0 -163
- package/dist/node/src/schema/embedding.d.ts +0 -193
- package/dist/node/src/schema/entity.d.ts +0 -122
- package/dist/node/src/schema/index.d.ts +0 -18
- package/dist/node/src/schema/log.d.ts +0 -114
- package/dist/node/src/schema/memory.d.ts +0 -188
- package/dist/node/src/schema/message.d.ts +0 -1
- package/dist/node/src/schema/messageServer.d.ts +0 -126
- package/dist/node/src/schema/messageServerAgent.d.ts +0 -41
- package/dist/node/src/schema/participant.d.ts +0 -114
- package/dist/node/src/schema/relationship.d.ts +0 -156
- package/dist/node/src/schema/room.d.ts +0 -192
- package/dist/node/src/schema/server.d.ts +0 -64
- package/dist/node/src/schema/tasks.d.ts +0 -225
- package/dist/node/src/schema/types.d.ts +0 -68
- package/dist/node/src/schema/world.d.ts +0 -114
- package/dist/node/src/types.d.ts +0 -15
- package/dist/node/src/utils.d.ts +0 -32
- package/dist/node/src/utils.node.d.ts +0 -6
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type IDatabaseAdapter, type UUID, type Plugin } from '@elizaos/core/browser';
|
|
2
|
-
/**
|
|
3
|
-
* Create a PGlite adapter for the browser (in-memory by default).
|
|
4
|
-
* No Postgres fallback in browser builds.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createDatabaseAdapter(_config: {
|
|
7
|
-
dataDir?: string;
|
|
8
|
-
}, agentId: UUID): IDatabaseAdapter;
|
|
9
|
-
export declare const plugin: Plugin;
|
|
10
|
-
export default plugin;
|
|
11
|
-
export { DatabaseMigrationService } from './migration-service';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { type Plugin } from '@elizaos/core';
|
|
2
|
-
import { RuntimeMigrator } from './runtime-migrator';
|
|
3
|
-
import type { DrizzleDatabase } from './types';
|
|
4
|
-
export declare class DatabaseMigrationService {
|
|
5
|
-
private db;
|
|
6
|
-
private registeredSchemas;
|
|
7
|
-
private migrator;
|
|
8
|
-
constructor();
|
|
9
|
-
/**
|
|
10
|
-
* Initialize service with database connection
|
|
11
|
-
* @param db - Drizzle database instance
|
|
12
|
-
*/
|
|
13
|
-
initializeWithDatabase(db: DrizzleDatabase): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Auto-discover and register schemas from plugins
|
|
16
|
-
* @param plugins - Array of plugins to scan for schemas
|
|
17
|
-
*/
|
|
18
|
-
discoverAndRegisterPluginSchemas(plugins: Plugin[]): void;
|
|
19
|
-
/**
|
|
20
|
-
* Register a schema for a specific plugin
|
|
21
|
-
* @param pluginName - Plugin identifier
|
|
22
|
-
* @param schema - Drizzle schema object
|
|
23
|
-
*/
|
|
24
|
-
registerSchema(pluginName: string, schema: any): void;
|
|
25
|
-
/**
|
|
26
|
-
* Run migrations for all registered plugins
|
|
27
|
-
* @param options - Migration options
|
|
28
|
-
* @param options.verbose - Log detailed output (default: true in dev, false in prod)
|
|
29
|
-
* @param options.force - Allow destructive migrations
|
|
30
|
-
* @param options.dryRun - Preview changes without applying
|
|
31
|
-
* @throws Error if any migration fails or destructive changes blocked
|
|
32
|
-
*/
|
|
33
|
-
runAllPluginMigrations(options?: {
|
|
34
|
-
verbose?: boolean;
|
|
35
|
-
force?: boolean;
|
|
36
|
-
dryRun?: boolean;
|
|
37
|
-
}): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Get the runtime migrator instance for advanced operations
|
|
40
|
-
* @returns RuntimeMigrator instance or null if not initialized
|
|
41
|
-
*/
|
|
42
|
-
getMigrator(): RuntimeMigrator | null;
|
|
43
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type IDatabaseAdapter } from '@elizaos/core';
|
|
2
|
-
/**
|
|
3
|
-
* TEMPORARY MIGRATION: develop → feat/entity-rls migration
|
|
4
|
-
*
|
|
5
|
-
* This migration runs automatically on startup and is idempotent.
|
|
6
|
-
* It handles the migration from Owner RLS to Server RLS + Entity RLS, including:
|
|
7
|
-
* - Disabling old RLS policies temporarily
|
|
8
|
-
* - Renaming server_id → message_server_id in channels, worlds, rooms
|
|
9
|
-
* - Converting TEXT → UUID where needed
|
|
10
|
-
* - Dropping old server_id columns for RLS
|
|
11
|
-
* - Cleaning up indexes
|
|
12
|
-
*
|
|
13
|
-
* @param adapter - Database adapter
|
|
14
|
-
*/
|
|
15
|
-
export declare function migrateToEntityRLS(adapter: IDatabaseAdapter): Promise<void>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { type UUID, type Agent, type Entity, type Memory } from '@elizaos/core';
|
|
2
|
-
import { BaseDrizzleAdapter } from '../base';
|
|
3
|
-
import { type EmbeddingDimensionColumn } from '../schema/embedding';
|
|
4
|
-
import type { PGliteClientManager } from './manager';
|
|
5
|
-
/**
|
|
6
|
-
* PgliteDatabaseAdapter class represents an adapter for interacting with a PgliteDatabase.
|
|
7
|
-
* Extends BaseDrizzleAdapter.
|
|
8
|
-
*
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param {UUID} agentId - The ID of the agent.
|
|
11
|
-
* @param {PGliteClientManager} manager - The manager for the Pglite client.
|
|
12
|
-
*
|
|
13
|
-
* @method withDatabase
|
|
14
|
-
* @param {() => Promise<T>} operation - The operation to perform on the database.
|
|
15
|
-
* @return {Promise<T>} - The result of the operation.
|
|
16
|
-
*
|
|
17
|
-
* @method init
|
|
18
|
-
* @return {Promise<void>} - A Promise that resolves when the initialization is complete.
|
|
19
|
-
*
|
|
20
|
-
* @method close
|
|
21
|
-
* @return {void} - A Promise that resolves when the database is closed.
|
|
22
|
-
*/
|
|
23
|
-
export declare class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
|
|
24
|
-
private manager;
|
|
25
|
-
protected embeddingDimension: EmbeddingDimensionColumn;
|
|
26
|
-
/**
|
|
27
|
-
* Constructor for creating an instance of a class.
|
|
28
|
-
* @param {UUID} agentId - The unique identifier for the agent.
|
|
29
|
-
* @param {PGliteClientManager} manager - The manager for the Pglite client.
|
|
30
|
-
*/
|
|
31
|
-
constructor(agentId: UUID, manager: PGliteClientManager);
|
|
32
|
-
/**
|
|
33
|
-
* Execute a callback with entity context for Entity RLS
|
|
34
|
-
* PGLite: No RLS support, just execute the callback in a simple transaction
|
|
35
|
-
*
|
|
36
|
-
* This is a public method because it's part of the adapter's public API
|
|
37
|
-
* for operations that need entity-scoped database access.
|
|
38
|
-
*/
|
|
39
|
-
withEntityContext<T>(_entityId: UUID | null, callback: (tx: any) => Promise<T>): Promise<T>;
|
|
40
|
-
getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
|
|
41
|
-
getMemoriesByServerId(_params: {
|
|
42
|
-
serverId: UUID;
|
|
43
|
-
count?: number;
|
|
44
|
-
}): Promise<Memory[]>;
|
|
45
|
-
ensureAgentExists(agent: Partial<Agent>): Promise<Agent>;
|
|
46
|
-
/**
|
|
47
|
-
* Asynchronously runs the provided database operation while checking if the database is currently shutting down.
|
|
48
|
-
* If the database is shutting down, a warning is logged and null is returned.
|
|
49
|
-
*
|
|
50
|
-
* @param {Function} operation - The database operation to be performed.
|
|
51
|
-
* @returns {Promise<T>} A promise that resolves with the result of the database operation.
|
|
52
|
-
*/
|
|
53
|
-
protected withDatabase<T>(operation: () => Promise<T>): Promise<T>;
|
|
54
|
-
/**
|
|
55
|
-
* Asynchronously initializes the database by running migrations.
|
|
56
|
-
*
|
|
57
|
-
* @returns {Promise<void>} A Promise that resolves when the database initialization is complete.
|
|
58
|
-
*/
|
|
59
|
-
init(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Checks if the database connection is ready and active.
|
|
62
|
-
* For PGLite, this checks if the client is not in a shutting down state.
|
|
63
|
-
* @returns {Promise<boolean>} A Promise that resolves to true if the connection is healthy.
|
|
64
|
-
*/
|
|
65
|
-
isReady(): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Asynchronously closes the database.
|
|
68
|
-
*/
|
|
69
|
-
close(): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Asynchronously retrieves the connection from the client.
|
|
72
|
-
*
|
|
73
|
-
* @returns {Promise<PGlite>} A Promise that resolves with the connection.
|
|
74
|
-
*/
|
|
75
|
-
getConnection(): Promise<import("@electric-sql/pglite").PGlite>;
|
|
76
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PGlite, type PGliteOptions } from '@electric-sql/pglite';
|
|
2
|
-
import type { IDatabaseClientManager } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Class representing a database client manager for PGlite.
|
|
5
|
-
* @implements { IDatabaseClientManager }
|
|
6
|
-
*/
|
|
7
|
-
export declare class PGliteClientManager implements IDatabaseClientManager<PGlite> {
|
|
8
|
-
private client;
|
|
9
|
-
private shuttingDown;
|
|
10
|
-
/**
|
|
11
|
-
* Constructor for creating a new instance of PGlite with the provided options.
|
|
12
|
-
* Initializes the PGlite client with additional extensions.
|
|
13
|
-
* @param {PGliteOptions} options - The options to configure the PGlite client.
|
|
14
|
-
*/
|
|
15
|
-
constructor(options: PGliteOptions);
|
|
16
|
-
getConnection(): PGlite;
|
|
17
|
-
isShuttingDown(): boolean;
|
|
18
|
-
initialize(): Promise<void>;
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
private setupShutdownHandlers;
|
|
21
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { type IDatabaseAdapter } from '@elizaos/core';
|
|
2
|
-
/**
|
|
3
|
-
* PostgreSQL Row-Level Security (RLS) for Multi-Server and Entity Isolation
|
|
4
|
-
*
|
|
5
|
-
* This module provides two layers of database-level security:
|
|
6
|
-
*
|
|
7
|
-
* 1. **Server RLS** - Multi-server isolation
|
|
8
|
-
* - Isolates data between different ElizaOS server instances
|
|
9
|
-
* - Uses `server_id` column added dynamically to all tables
|
|
10
|
-
* - Server context set via PostgreSQL `application_name` connection parameter
|
|
11
|
-
* - Prevents data leakage between different deployments/environments
|
|
12
|
-
*
|
|
13
|
-
* 2. **Entity RLS** - User/agent-level privacy isolation
|
|
14
|
-
* - Isolates data between different users (Clients (plugins/API) users)
|
|
15
|
-
* - Uses `entity_id`, `author_id`, or joins via `participants` table
|
|
16
|
-
* - Entity context set via `app.entity_id` transaction-local variable
|
|
17
|
-
* - Provides DM privacy and multi-user isolation within a server
|
|
18
|
-
*
|
|
19
|
-
* CRITICAL SECURITY REQUIREMENTS:
|
|
20
|
-
* - RLS policies DO NOT apply to PostgreSQL superuser accounts
|
|
21
|
-
* - Use a REGULAR (non-superuser) database user
|
|
22
|
-
* - Grant only necessary permissions (CREATE, SELECT, INSERT, UPDATE, DELETE)
|
|
23
|
-
* - NEVER use the 'postgres' superuser or any superuser account
|
|
24
|
-
* - Superusers bypass ALL RLS policies by design, defeating the isolation mechanism
|
|
25
|
-
*
|
|
26
|
-
* ARCHITECTURE:
|
|
27
|
-
* - Server RLS: Uses PostgreSQL `application_name` (set at connection pool level)
|
|
28
|
-
* - Entity RLS: Uses `SET LOCAL app.entity_id` (set per transaction)
|
|
29
|
-
* - Policies use FORCE ROW LEVEL SECURITY to enforce even for table owners
|
|
30
|
-
* - Automatic index creation for performance (`server_id`, `entity_id`, `room_id`)
|
|
31
|
-
*
|
|
32
|
-
* @module rls
|
|
33
|
-
*/
|
|
34
|
-
/**
|
|
35
|
-
* Install PostgreSQL functions required for Server RLS and Entity RLS
|
|
36
|
-
*
|
|
37
|
-
* This function creates all necessary PostgreSQL stored procedures for both
|
|
38
|
-
* Server RLS (multi-server isolation) and Entity RLS (user privacy isolation).
|
|
39
|
-
*
|
|
40
|
-
* **Server RLS Functions Created:**
|
|
41
|
-
* - `current_server_id()` - Returns server UUID from `application_name`
|
|
42
|
-
* - `add_server_isolation(schema, table)` - Adds Server RLS to a single table
|
|
43
|
-
* - `apply_rls_to_all_tables()` - Applies Server RLS to all eligible tables
|
|
44
|
-
*
|
|
45
|
-
* **Entity RLS Functions Created:**
|
|
46
|
-
* - `current_entity_id()` - Returns entity UUID from `app.entity_id` session variable
|
|
47
|
-
* - `add_entity_isolation(schema, table)` - Adds Entity RLS to a single table
|
|
48
|
-
* - `apply_entity_rls_to_all_tables()` - Applies Entity RLS to all eligible tables
|
|
49
|
-
*
|
|
50
|
-
* **Security Model:**
|
|
51
|
-
* - Server RLS: Isolation between different ElizaOS instances (environments/deployments)
|
|
52
|
-
* - Entity RLS: Isolation between different users within a server instance
|
|
53
|
-
* - Both layers stack - a user can only see data from their server AND their accessible entities
|
|
54
|
-
*
|
|
55
|
-
* **Important Notes:**
|
|
56
|
-
* - Must be called before `applyRLSToNewTables()` or `applyEntityRLSToAllTables()`
|
|
57
|
-
* - Creates `servers` table if it doesn't exist
|
|
58
|
-
* - Automatically calls `installEntityRLS()` to set up both layers
|
|
59
|
-
* - Uses `%I` identifier quoting in format() to prevent SQL injection
|
|
60
|
-
* - Policies use FORCE RLS to enforce even for table owners
|
|
61
|
-
*
|
|
62
|
-
* @param adapter - Database adapter with access to the Drizzle ORM instance
|
|
63
|
-
* @returns Promise that resolves when all RLS functions are installed
|
|
64
|
-
* @throws {Error} If database connection fails or SQL execution fails
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* // Install RLS functions on server startup
|
|
69
|
-
* await installRLSFunctions(database);
|
|
70
|
-
* await getOrCreateRlsServer(database, serverId);
|
|
71
|
-
* await setServerContext(database, serverId);
|
|
72
|
-
* await applyRLSToNewTables(database);
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function installRLSFunctions(adapter: IDatabaseAdapter): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Get or create RLS server using Drizzle ORM
|
|
78
|
-
*/
|
|
79
|
-
export declare function getOrCreateRlsServer(adapter: IDatabaseAdapter, serverId: string): Promise<string>;
|
|
80
|
-
/**
|
|
81
|
-
* Set RLS context on PostgreSQL connection pool
|
|
82
|
-
* This function validates that the server exists and has correct UUID format
|
|
83
|
-
*/
|
|
84
|
-
export declare function setServerContext(adapter: IDatabaseAdapter, serverId: string): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Assign agent to server using Drizzle ORM
|
|
87
|
-
*/
|
|
88
|
-
export declare function assignAgentToServer(adapter: IDatabaseAdapter, agentId: string, serverId: string): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Apply RLS to all tables by calling PostgreSQL function
|
|
91
|
-
*/
|
|
92
|
-
export declare function applyRLSToNewTables(adapter: IDatabaseAdapter): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Disable RLS globally
|
|
95
|
-
* SIMPLE APPROACH:
|
|
96
|
-
* - Disables RLS for ALL server instances
|
|
97
|
-
* - Keeps server_id columns and data intact
|
|
98
|
-
* - Use only in development or when migrating to single-server mode
|
|
99
|
-
*/
|
|
100
|
-
export declare function uninstallRLS(adapter: IDatabaseAdapter): Promise<void>;
|
|
101
|
-
/**
|
|
102
|
-
* Install Entity RLS functions for user privacy isolation
|
|
103
|
-
*
|
|
104
|
-
* This provides database-level privacy between different entities (client users: Plugins/API)
|
|
105
|
-
* interacting with agents, independent of JWT authentication.
|
|
106
|
-
*
|
|
107
|
-
* **How Entity RLS Works:**
|
|
108
|
-
* - Each database transaction sets `app.entity_id` before querying
|
|
109
|
-
* - Policies filter rows based on entity ownership or participant membership
|
|
110
|
-
* - Two isolation strategies:
|
|
111
|
-
* 1. Direct ownership: `entity_id` or `author_id` column matches `current_entity_id()`
|
|
112
|
-
* 2. Shared access: `room_id`/`channel_id` exists in `participants` table for the entity
|
|
113
|
-
*
|
|
114
|
-
* **Performance Considerations:**
|
|
115
|
-
* - **Subquery policies** (for `room_id`/`channel_id`) run on EVERY row access
|
|
116
|
-
* - Indexes are automatically created on: `entity_id`, `author_id`, `room_id`, `channel_id`
|
|
117
|
-
* - The `participants` table should have an index on `(entity_id, channel_id)`
|
|
118
|
-
* - For large datasets (>1M rows), consider:
|
|
119
|
-
* - Materialized views for frequently accessed entity-filtered data
|
|
120
|
-
* - Partitioning large tables by date or entity_id
|
|
121
|
-
*
|
|
122
|
-
* **Optimization Tips:**
|
|
123
|
-
* - Direct column policies (`entity_id = current_entity_id()`) are faster than subquery policies
|
|
124
|
-
* - The `participants` lookup is cached per transaction but still requires index scans
|
|
125
|
-
*
|
|
126
|
-
* **Tables Excluded from Entity RLS:**
|
|
127
|
-
* - `servers` - Server RLS table
|
|
128
|
-
* - `users` - Authentication (no entity isolation)
|
|
129
|
-
* - `entity_mappings` - Cross-platform entity mapping
|
|
130
|
-
* - `drizzle_migrations`, `__drizzle_migrations` - Migration tracking
|
|
131
|
-
*
|
|
132
|
-
* @param adapter - Database adapter with access to the Drizzle ORM instance
|
|
133
|
-
* @returns Promise that resolves when Entity RLS functions are installed
|
|
134
|
-
* @throws {Error} If database connection fails or SQL execution fails
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* // Called automatically by installRLSFunctions()
|
|
139
|
-
* await installRLSFunctions(database);
|
|
140
|
-
*
|
|
141
|
-
* // Or call separately if needed
|
|
142
|
-
* await installEntityRLS(database);
|
|
143
|
-
* await applyEntityRLSToAllTables(database);
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export declare function installEntityRLS(adapter: IDatabaseAdapter): Promise<void>;
|
|
147
|
-
/**
|
|
148
|
-
* Apply Entity RLS policies to all eligible tables
|
|
149
|
-
* Call this after installEntityRLS() to activate the policies
|
|
150
|
-
*/
|
|
151
|
-
export declare function applyEntityRLSToAllTables(adapter: IDatabaseAdapter): Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Remove Entity RLS (for rollback or testing)
|
|
154
|
-
* Drops entity RLS functions and policies but keeps server RLS intact
|
|
155
|
-
*/
|
|
156
|
-
export declare function uninstallEntityRLS(adapter: IDatabaseAdapter): Promise<void>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { DrizzleDB, SchemaSnapshot } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Introspect the current database state and generate a snapshot
|
|
4
|
-
* This is used when no previous snapshot exists for a plugin
|
|
5
|
-
* to capture the existing database state before migrations
|
|
6
|
-
*/
|
|
7
|
-
export declare class DatabaseIntrospector {
|
|
8
|
-
private db;
|
|
9
|
-
constructor(db: DrizzleDB);
|
|
10
|
-
/**
|
|
11
|
-
* Introspect all tables in the database and generate a snapshot
|
|
12
|
-
* @param schemaName - Schema to introspect (default: 'public')
|
|
13
|
-
* @returns Schema snapshot of current database state
|
|
14
|
-
*/
|
|
15
|
-
introspectSchema(schemaName?: string): Promise<SchemaSnapshot>;
|
|
16
|
-
/**
|
|
17
|
-
* Get all tables in a schema
|
|
18
|
-
*/
|
|
19
|
-
private getTables;
|
|
20
|
-
/**
|
|
21
|
-
* Get columns for a table
|
|
22
|
-
*/
|
|
23
|
-
private getColumns;
|
|
24
|
-
/**
|
|
25
|
-
* Get indexes for a table
|
|
26
|
-
*/
|
|
27
|
-
private getIndexes;
|
|
28
|
-
/**
|
|
29
|
-
* Get foreign keys for a table
|
|
30
|
-
*/
|
|
31
|
-
private getForeignKeys;
|
|
32
|
-
/**
|
|
33
|
-
* Get primary keys for a table
|
|
34
|
-
*/
|
|
35
|
-
private getPrimaryKeys;
|
|
36
|
-
/**
|
|
37
|
-
* Get unique constraints for a table
|
|
38
|
-
*/
|
|
39
|
-
private getUniqueConstraints;
|
|
40
|
-
/**
|
|
41
|
-
* Get check constraints for a table
|
|
42
|
-
*/
|
|
43
|
-
private getCheckConstraints;
|
|
44
|
-
/**
|
|
45
|
-
* Get enums in a schema
|
|
46
|
-
*/
|
|
47
|
-
private getEnums;
|
|
48
|
-
/**
|
|
49
|
-
* Parse default value for a column
|
|
50
|
-
*/
|
|
51
|
-
private parseDefault;
|
|
52
|
-
/**
|
|
53
|
-
* Check if tables exist for a plugin by checking if any tables exist in its schema
|
|
54
|
-
* @param pluginName - Name of the plugin
|
|
55
|
-
* @returns True if tables exist, false otherwise
|
|
56
|
-
*/
|
|
57
|
-
hasExistingTables(pluginName: string): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Derive schema name from plugin name
|
|
60
|
-
*/
|
|
61
|
-
private deriveSchemaName;
|
|
62
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { SchemaSnapshot } from '../types';
|
|
2
|
-
export interface SchemaDiff {
|
|
3
|
-
tables: {
|
|
4
|
-
created: string[];
|
|
5
|
-
deleted: string[];
|
|
6
|
-
modified: Array<{
|
|
7
|
-
name: string;
|
|
8
|
-
changes: any;
|
|
9
|
-
}>;
|
|
10
|
-
};
|
|
11
|
-
columns: {
|
|
12
|
-
added: Array<{
|
|
13
|
-
table: string;
|
|
14
|
-
column: string;
|
|
15
|
-
definition: any;
|
|
16
|
-
}>;
|
|
17
|
-
deleted: Array<{
|
|
18
|
-
table: string;
|
|
19
|
-
column: string;
|
|
20
|
-
}>;
|
|
21
|
-
modified: Array<{
|
|
22
|
-
table: string;
|
|
23
|
-
column: string;
|
|
24
|
-
changes: any;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
indexes: {
|
|
28
|
-
created: any[];
|
|
29
|
-
deleted: any[];
|
|
30
|
-
altered: Array<{
|
|
31
|
-
old: any;
|
|
32
|
-
new: any;
|
|
33
|
-
}>;
|
|
34
|
-
};
|
|
35
|
-
foreignKeys: {
|
|
36
|
-
created: any[];
|
|
37
|
-
deleted: any[];
|
|
38
|
-
altered: Array<{
|
|
39
|
-
old: any;
|
|
40
|
-
new: any;
|
|
41
|
-
}>;
|
|
42
|
-
};
|
|
43
|
-
uniqueConstraints: {
|
|
44
|
-
created: any[];
|
|
45
|
-
deleted: any[];
|
|
46
|
-
};
|
|
47
|
-
checkConstraints: {
|
|
48
|
-
created: any[];
|
|
49
|
-
deleted: any[];
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Calculate the difference between two snapshots
|
|
54
|
-
*/
|
|
55
|
-
export declare function calculateDiff(previousSnapshot: SchemaSnapshot | null, currentSnapshot: SchemaSnapshot): Promise<SchemaDiff>;
|
|
56
|
-
/**
|
|
57
|
-
* Check if a diff has any changes
|
|
58
|
-
*/
|
|
59
|
-
export declare function hasDiffChanges(diff: SchemaDiff): boolean;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SchemaSnapshot } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Generate a snapshot from a Drizzle schema
|
|
4
|
-
* This is a port of Drizzle's pgSerializer.generatePgSnapshot
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateSnapshot(schema: any): Promise<SchemaSnapshot>;
|
|
7
|
-
/**
|
|
8
|
-
* Calculate hash of a snapshot for change detection
|
|
9
|
-
*/
|
|
10
|
-
export declare function hashSnapshot(snapshot: SchemaSnapshot): string;
|
|
11
|
-
/**
|
|
12
|
-
* Create an empty snapshot for initial migration
|
|
13
|
-
*/
|
|
14
|
-
export declare function createEmptySnapshot(): SchemaSnapshot;
|
|
15
|
-
/**
|
|
16
|
-
* Compare two snapshots and detect if there are changes
|
|
17
|
-
*/
|
|
18
|
-
export declare function hasChanges(previousSnapshot: SchemaSnapshot | null, currentSnapshot: SchemaSnapshot): boolean;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { SchemaSnapshot } from '../types';
|
|
2
|
-
import type { SchemaDiff } from './diff-calculator';
|
|
3
|
-
/**
|
|
4
|
-
* Data loss detection result
|
|
5
|
-
* Based on Drizzle's pgPushUtils approach
|
|
6
|
-
*/
|
|
7
|
-
export interface DataLossCheck {
|
|
8
|
-
hasDataLoss: boolean;
|
|
9
|
-
tablesToRemove: string[];
|
|
10
|
-
columnsToRemove: string[];
|
|
11
|
-
tablesToTruncate: string[];
|
|
12
|
-
typeChanges: Array<{
|
|
13
|
-
table: string;
|
|
14
|
-
column: string;
|
|
15
|
-
from: string;
|
|
16
|
-
to: string;
|
|
17
|
-
}>;
|
|
18
|
-
warnings: string[];
|
|
19
|
-
requiresConfirmation: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Check for potential data loss in schema changes
|
|
23
|
-
* Based on Drizzle's pgSuggestions function
|
|
24
|
-
*/
|
|
25
|
-
export declare function checkForDataLoss(diff: SchemaDiff): DataLossCheck;
|
|
26
|
-
/**
|
|
27
|
-
* Generate SQL statements from a schema diff
|
|
28
|
-
* This follows Drizzle's approach: create all tables first, then add foreign keys
|
|
29
|
-
*/
|
|
30
|
-
export declare function generateMigrationSQL(previousSnapshot: SchemaSnapshot | null, currentSnapshot: SchemaSnapshot, diff?: SchemaDiff): Promise<string[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Generate SQL for renaming a table
|
|
33
|
-
*/
|
|
34
|
-
export declare function generateRenameTableSQL(oldName: string, newName: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Generate SQL for renaming a column
|
|
37
|
-
*/
|
|
38
|
-
export declare function generateRenameColumnSQL(table: string, oldName: string, newName: string): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { RuntimeMigrator } from './runtime-migrator';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export { MigrationTracker } from './storage/migration-tracker';
|
|
4
|
-
export { JournalStorage } from './storage/journal-storage';
|
|
5
|
-
export { SnapshotStorage } from './storage/snapshot-storage';
|
|
6
|
-
export { generateSnapshot, hashSnapshot, createEmptySnapshot, hasChanges, } from './drizzle-adapters/snapshot-generator';
|
|
7
|
-
export { calculateDiff, hasDiffChanges, type SchemaDiff } from './drizzle-adapters/diff-calculator';
|
|
8
|
-
export { generateMigrationSQL, generateRenameTableSQL, generateRenameColumnSQL, } from './drizzle-adapters/sql-generator';
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { DrizzleDB, RuntimeMigrationOptions } from './types';
|
|
2
|
-
import { type DataLossCheck } from './drizzle-adapters/sql-generator';
|
|
3
|
-
export declare class RuntimeMigrator {
|
|
4
|
-
private db;
|
|
5
|
-
private migrationTracker;
|
|
6
|
-
private journalStorage;
|
|
7
|
-
private snapshotStorage;
|
|
8
|
-
private extensionManager;
|
|
9
|
-
private introspector;
|
|
10
|
-
constructor(db: DrizzleDB);
|
|
11
|
-
/**
|
|
12
|
-
* Get expected schema name for a plugin
|
|
13
|
-
* @elizaos/plugin-sql uses 'public' schema (core application)
|
|
14
|
-
* All other plugins should use namespaced schemas
|
|
15
|
-
*/
|
|
16
|
-
private getExpectedSchemaName;
|
|
17
|
-
/**
|
|
18
|
-
* Ensure all schemas used in the snapshot exist
|
|
19
|
-
*/
|
|
20
|
-
private ensureSchemasExist;
|
|
21
|
-
/**
|
|
22
|
-
* Validate schema usage and provide warnings
|
|
23
|
-
*/
|
|
24
|
-
private validateSchemaUsage;
|
|
25
|
-
/**
|
|
26
|
-
* Generate a stable advisory lock ID from plugin name
|
|
27
|
-
* PostgreSQL advisory locks use bigint, so we need to hash the plugin name
|
|
28
|
-
* and convert to a stable bigint value
|
|
29
|
-
*/
|
|
30
|
-
private getAdvisoryLockId;
|
|
31
|
-
/**
|
|
32
|
-
* Validate that a value is a valid PostgreSQL bigint
|
|
33
|
-
* PostgreSQL bigint range: -9223372036854775808 to 9223372036854775807
|
|
34
|
-
*/
|
|
35
|
-
private validateBigInt;
|
|
36
|
-
/**
|
|
37
|
-
* Detect if a connection string represents a real PostgreSQL database
|
|
38
|
-
* (not PGLite, in-memory, or other non-PostgreSQL databases)
|
|
39
|
-
*
|
|
40
|
-
* This method handles various connection string formats including:
|
|
41
|
-
* - Standard postgres:// and postgresql:// URLs
|
|
42
|
-
* - Cloud provider URLs (AWS, Azure, GCP, Supabase, Neon, etc.)
|
|
43
|
-
* - Connection strings with query parameters
|
|
44
|
-
* - Non-standard schemes (pgbouncer://, etc.)
|
|
45
|
-
* - IP addresses with ports
|
|
46
|
-
*
|
|
47
|
-
* @param connectionUrl - Database connection string to check
|
|
48
|
-
* @returns true if this is a real PostgreSQL database connection
|
|
49
|
-
*/
|
|
50
|
-
private isRealPostgresDatabase;
|
|
51
|
-
/**
|
|
52
|
-
* Initialize migration system - create necessary tables
|
|
53
|
-
* @throws Error if table creation fails
|
|
54
|
-
*/
|
|
55
|
-
initialize(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Run migrations for a plugin/schema
|
|
58
|
-
* @param pluginName - Plugin identifier
|
|
59
|
-
* @param schema - Drizzle schema object
|
|
60
|
-
* @param options - Migration options (verbose, force, dryRun, allowDataLoss)
|
|
61
|
-
* @throws Error if destructive migrations blocked or migration fails
|
|
62
|
-
*/
|
|
63
|
-
migrate(pluginName: string, schema: any, options?: RuntimeMigrationOptions): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Execute migration in a transaction
|
|
66
|
-
*/
|
|
67
|
-
private executeMigration;
|
|
68
|
-
/**
|
|
69
|
-
* Generate migration tag (like 0000_jazzy_shard)
|
|
70
|
-
*/
|
|
71
|
-
private generateMigrationTag;
|
|
72
|
-
/**
|
|
73
|
-
* Get migration status for a plugin
|
|
74
|
-
* @param pluginName - Plugin identifier
|
|
75
|
-
* @returns Migration history and current state
|
|
76
|
-
*/
|
|
77
|
-
getStatus(pluginName: string): Promise<{
|
|
78
|
-
hasRun: boolean;
|
|
79
|
-
lastMigration: any;
|
|
80
|
-
journal: any;
|
|
81
|
-
snapshots: number;
|
|
82
|
-
}>;
|
|
83
|
-
/**
|
|
84
|
-
* Reset migrations for a plugin (dangerous - for development only)
|
|
85
|
-
* @param pluginName - Plugin identifier
|
|
86
|
-
* @warning Deletes all migration history - use only in development
|
|
87
|
-
*/
|
|
88
|
-
reset(pluginName: string): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Check if a migration would cause data loss without executing it
|
|
91
|
-
* @param pluginName - Plugin identifier
|
|
92
|
-
* @param schema - Drizzle schema to check
|
|
93
|
-
* @returns Data loss analysis or null if no changes
|
|
94
|
-
*/
|
|
95
|
-
checkMigration(pluginName: string, schema: any): Promise<DataLossCheck | null>;
|
|
96
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transform a plugin's schema to use the appropriate namespace
|
|
3
|
-
*
|
|
4
|
-
* @elizaos/plugin-sql uses 'public' schema (no transformation)
|
|
5
|
-
* Other plugins get their tables wrapped in a namespaced schema
|
|
6
|
-
*/
|
|
7
|
-
export declare function transformPluginSchema(pluginName: string, schema: any): any;
|
|
8
|
-
/**
|
|
9
|
-
* Derive a valid PostgreSQL schema name from a plugin name
|
|
10
|
-
*/
|
|
11
|
-
export declare function deriveSchemaName(pluginName: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Create a namespaced schema helper for plugins
|
|
14
|
-
* This is what plugins should ideally use to define their tables
|
|
15
|
-
*/
|
|
16
|
-
export declare function createPluginSchema(pluginName: string): import("drizzle-orm/pg-core").PgSchema<string>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { DrizzleDB, Journal, JournalEntry } from '../types';
|
|
2
|
-
export declare class JournalStorage {
|
|
3
|
-
private db;
|
|
4
|
-
constructor(db: DrizzleDB);
|
|
5
|
-
loadJournal(pluginName: string): Promise<Journal | null>;
|
|
6
|
-
saveJournal(pluginName: string, journal: Journal): Promise<void>;
|
|
7
|
-
addEntry(pluginName: string, entry: JournalEntry): Promise<void>;
|
|
8
|
-
getNextIdx(pluginName: string): Promise<number>;
|
|
9
|
-
updateJournal(pluginName: string, idx: number, tag: string, breakpoints?: boolean): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { DrizzleDB } from '../types';
|
|
2
|
-
export declare class MigrationTracker {
|
|
3
|
-
private db;
|
|
4
|
-
constructor(db: DrizzleDB);
|
|
5
|
-
ensureSchema(): Promise<void>;
|
|
6
|
-
ensureTables(): Promise<void>;
|
|
7
|
-
getLastMigration(pluginName: string): Promise<{
|
|
8
|
-
id: number;
|
|
9
|
-
hash: string;
|
|
10
|
-
created_at: string;
|
|
11
|
-
} | null>;
|
|
12
|
-
recordMigration(pluginName: string, hash: string, createdAt: number): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { DrizzleDB, SchemaSnapshot } from '../types';
|
|
2
|
-
export declare class SnapshotStorage {
|
|
3
|
-
private db;
|
|
4
|
-
constructor(db: DrizzleDB);
|
|
5
|
-
saveSnapshot(pluginName: string, idx: number, snapshot: SchemaSnapshot): Promise<void>;
|
|
6
|
-
loadSnapshot(pluginName: string, idx: number): Promise<SchemaSnapshot | null>;
|
|
7
|
-
getLatestSnapshot(pluginName: string): Promise<SchemaSnapshot | null>;
|
|
8
|
-
getAllSnapshots(pluginName: string): Promise<SchemaSnapshot[]>;
|
|
9
|
-
}
|