@elizaos/plugin-sql 1.6.5-alpha.9 → 1.6.5

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.
Files changed (130) hide show
  1. package/dist/browser/index.browser.js +1907 -436
  2. package/dist/browser/index.browser.js.map +26 -23
  3. package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
  4. package/dist/node/index.d.ts +2 -2
  5. package/dist/node/index.node.js +1436 -662
  6. package/dist/node/index.node.js.map +33 -31
  7. package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
  8. package/package.json +17 -14
  9. package/dist/browser/base.d.ts +0 -926
  10. package/dist/browser/index.browser.d.ts +0 -11
  11. package/dist/browser/migration-service.d.ts +0 -43
  12. package/dist/browser/pglite/adapter.d.ts +0 -68
  13. package/dist/browser/pglite/manager.d.ts +0 -21
  14. package/dist/browser/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
  15. package/dist/browser/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
  16. package/dist/browser/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
  17. package/dist/browser/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
  18. package/dist/browser/runtime-migrator/extension-manager.d.ts +0 -6
  19. package/dist/browser/runtime-migrator/index.d.ts +0 -8
  20. package/dist/browser/runtime-migrator/runtime-migrator.d.ts +0 -96
  21. package/dist/browser/runtime-migrator/schema-transformer.d.ts +0 -16
  22. package/dist/browser/runtime-migrator/storage/journal-storage.d.ts +0 -10
  23. package/dist/browser/runtime-migrator/storage/migration-tracker.d.ts +0 -13
  24. package/dist/browser/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
  25. package/dist/browser/runtime-migrator/types.d.ts +0 -48
  26. package/dist/browser/schema/agent.d.ts +0 -344
  27. package/dist/browser/schema/cache.d.ts +0 -97
  28. package/dist/browser/schema/channel.d.ts +0 -177
  29. package/dist/browser/schema/channelParticipant.d.ts +0 -41
  30. package/dist/browser/schema/component.d.ts +0 -163
  31. package/dist/browser/schema/embedding.d.ts +0 -193
  32. package/dist/browser/schema/entity.d.ts +0 -122
  33. package/dist/browser/schema/index.d.ts +0 -18
  34. package/dist/browser/schema/log.d.ts +0 -114
  35. package/dist/browser/schema/memory.d.ts +0 -188
  36. package/dist/browser/schema/message.d.ts +0 -1
  37. package/dist/browser/schema/messageServer.d.ts +0 -126
  38. package/dist/browser/schema/owners.d.ts +0 -63
  39. package/dist/browser/schema/participant.d.ts +0 -114
  40. package/dist/browser/schema/relationship.d.ts +0 -156
  41. package/dist/browser/schema/room.d.ts +0 -192
  42. package/dist/browser/schema/serverAgent.d.ts +0 -41
  43. package/dist/browser/schema/tasks.d.ts +0 -225
  44. package/dist/browser/schema/types.d.ts +0 -68
  45. package/dist/browser/schema/world.d.ts +0 -114
  46. package/dist/browser/src/base.d.ts +0 -926
  47. package/dist/browser/src/index.browser.d.ts +0 -11
  48. package/dist/browser/src/migration-service.d.ts +0 -43
  49. package/dist/browser/src/pglite/adapter.d.ts +0 -68
  50. package/dist/browser/src/pglite/manager.d.ts +0 -21
  51. package/dist/browser/src/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
  52. package/dist/browser/src/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
  53. package/dist/browser/src/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
  54. package/dist/browser/src/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
  55. package/dist/browser/src/runtime-migrator/extension-manager.d.ts +0 -6
  56. package/dist/browser/src/runtime-migrator/index.d.ts +0 -8
  57. package/dist/browser/src/runtime-migrator/runtime-migrator.d.ts +0 -96
  58. package/dist/browser/src/runtime-migrator/schema-transformer.d.ts +0 -16
  59. package/dist/browser/src/runtime-migrator/storage/journal-storage.d.ts +0 -10
  60. package/dist/browser/src/runtime-migrator/storage/migration-tracker.d.ts +0 -13
  61. package/dist/browser/src/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
  62. package/dist/browser/src/runtime-migrator/types.d.ts +0 -48
  63. package/dist/browser/src/schema/agent.d.ts +0 -344
  64. package/dist/browser/src/schema/cache.d.ts +0 -97
  65. package/dist/browser/src/schema/channel.d.ts +0 -177
  66. package/dist/browser/src/schema/channelParticipant.d.ts +0 -41
  67. package/dist/browser/src/schema/component.d.ts +0 -163
  68. package/dist/browser/src/schema/embedding.d.ts +0 -193
  69. package/dist/browser/src/schema/entity.d.ts +0 -122
  70. package/dist/browser/src/schema/index.d.ts +0 -18
  71. package/dist/browser/src/schema/log.d.ts +0 -114
  72. package/dist/browser/src/schema/memory.d.ts +0 -188
  73. package/dist/browser/src/schema/message.d.ts +0 -1
  74. package/dist/browser/src/schema/messageServer.d.ts +0 -126
  75. package/dist/browser/src/schema/owners.d.ts +0 -63
  76. package/dist/browser/src/schema/participant.d.ts +0 -114
  77. package/dist/browser/src/schema/relationship.d.ts +0 -156
  78. package/dist/browser/src/schema/room.d.ts +0 -192
  79. package/dist/browser/src/schema/serverAgent.d.ts +0 -41
  80. package/dist/browser/src/schema/tasks.d.ts +0 -225
  81. package/dist/browser/src/schema/types.d.ts +0 -68
  82. package/dist/browser/src/schema/world.d.ts +0 -114
  83. package/dist/browser/src/types.d.ts +0 -15
  84. package/dist/browser/src/utils.browser.d.ts +0 -21
  85. package/dist/browser/types.d.ts +0 -15
  86. package/dist/browser/utils.browser.d.ts +0 -21
  87. package/dist/node/src/base.d.ts +0 -926
  88. package/dist/node/src/index.d.ts +0 -33
  89. package/dist/node/src/index.node.d.ts +0 -10
  90. package/dist/node/src/migration-service.d.ts +0 -43
  91. package/dist/node/src/pg/adapter.d.ts +0 -69
  92. package/dist/node/src/pg/manager.d.ts +0 -17
  93. package/dist/node/src/pglite/adapter.d.ts +0 -68
  94. package/dist/node/src/pglite/manager.d.ts +0 -21
  95. package/dist/node/src/rls.d.ts +0 -43
  96. package/dist/node/src/runtime-migrator/drizzle-adapters/database-introspector.d.ts +0 -62
  97. package/dist/node/src/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +0 -59
  98. package/dist/node/src/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +0 -18
  99. package/dist/node/src/runtime-migrator/drizzle-adapters/sql-generator.d.ts +0 -38
  100. package/dist/node/src/runtime-migrator/extension-manager.d.ts +0 -6
  101. package/dist/node/src/runtime-migrator/index.d.ts +0 -8
  102. package/dist/node/src/runtime-migrator/runtime-migrator.d.ts +0 -96
  103. package/dist/node/src/runtime-migrator/schema-transformer.d.ts +0 -16
  104. package/dist/node/src/runtime-migrator/storage/journal-storage.d.ts +0 -10
  105. package/dist/node/src/runtime-migrator/storage/migration-tracker.d.ts +0 -13
  106. package/dist/node/src/runtime-migrator/storage/snapshot-storage.d.ts +0 -9
  107. package/dist/node/src/runtime-migrator/types.d.ts +0 -48
  108. package/dist/node/src/schema/agent.d.ts +0 -344
  109. package/dist/node/src/schema/cache.d.ts +0 -97
  110. package/dist/node/src/schema/channel.d.ts +0 -177
  111. package/dist/node/src/schema/channelParticipant.d.ts +0 -41
  112. package/dist/node/src/schema/component.d.ts +0 -163
  113. package/dist/node/src/schema/embedding.d.ts +0 -193
  114. package/dist/node/src/schema/entity.d.ts +0 -122
  115. package/dist/node/src/schema/index.d.ts +0 -18
  116. package/dist/node/src/schema/log.d.ts +0 -114
  117. package/dist/node/src/schema/memory.d.ts +0 -188
  118. package/dist/node/src/schema/message.d.ts +0 -1
  119. package/dist/node/src/schema/messageServer.d.ts +0 -126
  120. package/dist/node/src/schema/owners.d.ts +0 -63
  121. package/dist/node/src/schema/participant.d.ts +0 -114
  122. package/dist/node/src/schema/relationship.d.ts +0 -156
  123. package/dist/node/src/schema/room.d.ts +0 -192
  124. package/dist/node/src/schema/serverAgent.d.ts +0 -41
  125. package/dist/node/src/schema/tasks.d.ts +0 -225
  126. package/dist/node/src/schema/types.d.ts +0 -68
  127. package/dist/node/src/schema/world.d.ts +0 -114
  128. package/dist/node/src/types.d.ts +0 -15
  129. package/dist/node/src/utils.d.ts +0 -32
  130. package/dist/node/src/utils.node.d.ts +0 -6
@@ -1,33 +0,0 @@
1
- import type { IDatabaseAdapter, UUID } from '@elizaos/core';
2
- import { type Plugin } from '@elizaos/core';
3
- import * as schema from './schema';
4
- /**
5
- * Creates a database adapter based on the provided configuration.
6
- * If a postgresUrl is provided in the config, a PgDatabaseAdapter is initialized using the PostgresConnectionManager.
7
- * If no postgresUrl is provided, a PgliteDatabaseAdapter is initialized using PGliteClientManager with the dataDir from the config.
8
- *
9
- * @param {object} config - The configuration object.
10
- * @param {string} [config.dataDir] - The directory where data is stored. Defaults to "./.eliza/.elizadb".
11
- * @param {string} [config.postgresUrl] - The URL for the PostgreSQL database.
12
- * @param {UUID} agentId - The unique identifier for the agent.
13
- * @returns {IDatabaseAdapter} The created database adapter.
14
- */
15
- export declare function createDatabaseAdapter(config: {
16
- dataDir?: string;
17
- postgresUrl?: string;
18
- }, agentId: UUID): IDatabaseAdapter;
19
- /**
20
- * SQL plugin for database adapter using Drizzle ORM with dynamic plugin schema migrations
21
- *
22
- * @typedef {Object} Plugin
23
- * @property {string} name - The name of the plugin
24
- * @property {string} description - The description of the plugin
25
- * @property {Function} init - The initialization function for the plugin
26
- * @param {any} _ - Input parameter
27
- * @param {IAgentRuntime} runtime - The runtime environment for the agent
28
- */
29
- export declare const plugin: Plugin;
30
- export default plugin;
31
- export { DatabaseMigrationService } from './migration-service';
32
- export { installRLSFunctions, getOrCreateRlsOwner, setOwnerContext, assignAgentToOwner, applyRLSToNewTables, uninstallRLS, } from './rls';
33
- export { schema };
@@ -1,10 +0,0 @@
1
- import type { IDatabaseAdapter, UUID } from '@elizaos/core';
2
- import { type Plugin } from '@elizaos/core';
3
- export declare function createDatabaseAdapter(config: {
4
- dataDir?: string;
5
- postgresUrl?: string;
6
- }, agentId: UUID): IDatabaseAdapter;
7
- export declare const plugin: Plugin;
8
- export default plugin;
9
- export { DatabaseMigrationService } from './migration-service';
10
- export { installRLSFunctions, getOrCreateRlsOwner, setOwnerContext, assignAgentToOwner, applyRLSToNewTables, uninstallRLS, } from './rls';
@@ -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,69 +0,0 @@
1
- import { type UUID, Agent, Entity, Memory, Component } from '@elizaos/core';
2
- import { BaseDrizzleAdapter } from '../base';
3
- import { type EmbeddingDimensionColumn } from '../schema/embedding';
4
- import type { PostgresConnectionManager } from './manager';
5
- /**
6
- * Adapter class for interacting with a PostgreSQL database.
7
- * Extends BaseDrizzleAdapter.
8
- */
9
- export declare class PgDatabaseAdapter extends BaseDrizzleAdapter {
10
- protected embeddingDimension: EmbeddingDimensionColumn;
11
- private manager;
12
- constructor(agentId: UUID, manager: PostgresConnectionManager, _schema?: any);
13
- getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
14
- getMemoriesByServerId(_params: {
15
- serverId: UUID;
16
- count?: number;
17
- }): Promise<Memory[]>;
18
- ensureAgentExists(agent: Partial<Agent>): Promise<Agent>;
19
- /**
20
- * Executes the provided operation with a database connection.
21
- *
22
- * @template T
23
- * @param {() => Promise<T>} operation - The operation to be executed with the database connection.
24
- * @returns {Promise<T>} A promise that resolves with the result of the operation.
25
- */
26
- protected withDatabase<T>(operation: () => Promise<T>): Promise<T>;
27
- /**
28
- * Asynchronously initializes the PgDatabaseAdapter by running migrations using the manager.
29
- * Logs a success message if initialization is successful, otherwise logs an error message.
30
- *
31
- * @returns {Promise<void>} A promise that resolves when initialization is complete.
32
- */
33
- init(): Promise<void>;
34
- /**
35
- * Checks if the database connection is ready and active.
36
- * @returns {Promise<boolean>} A Promise that resolves to true if the connection is healthy.
37
- */
38
- isReady(): Promise<boolean>;
39
- /**
40
- * Asynchronously closes the manager associated with this instance.
41
- *
42
- * @returns A Promise that resolves once the manager is closed.
43
- */
44
- close(): Promise<void>;
45
- /**
46
- * Asynchronously retrieves the connection from the manager.
47
- *
48
- * @returns {Promise<Pool>} A Promise that resolves with the connection.
49
- */
50
- getConnection(): Promise<import("pg").Pool>;
51
- createAgent(agent: Agent): Promise<boolean>;
52
- getAgent(agentId: UUID): Promise<Agent | null>;
53
- updateAgent(agentId: UUID, agent: Partial<Agent>): Promise<boolean>;
54
- deleteAgent(agentId: UUID): Promise<boolean>;
55
- createEntities(entities: Entity[]): Promise<boolean>;
56
- getEntitiesByIds(entityIds: UUID[]): Promise<Entity[]>;
57
- updateEntity(entity: Entity): Promise<void>;
58
- createMemory(memory: Memory, tableName: string): Promise<UUID>;
59
- getMemoryById(memoryId: UUID): Promise<Memory | null>;
60
- searchMemories(params: any): Promise<any[]>;
61
- updateMemory(memory: Partial<Memory> & {
62
- id: UUID;
63
- }): Promise<boolean>;
64
- deleteMemory(memoryId: UUID): Promise<void>;
65
- createComponent(component: Component): Promise<boolean>;
66
- getComponent(entityId: UUID, type: string, worldId?: UUID, sourceEntityId?: UUID): Promise<Component | null>;
67
- updateComponent(component: Component): Promise<void>;
68
- deleteComponent(componentId: UUID): Promise<void>;
69
- }
@@ -1,17 +0,0 @@
1
- import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
2
- import { Pool, type PoolClient } from 'pg';
3
- export declare class PostgresConnectionManager {
4
- private pool;
5
- private db;
6
- constructor(connectionString: string, rlsOwnerId?: string);
7
- getDatabase(): NodePgDatabase;
8
- getConnection(): Pool;
9
- getClient(): Promise<PoolClient>;
10
- testConnection(): Promise<boolean>;
11
- /**
12
- * Closes the connection pool.
13
- * @returns {Promise<void>}
14
- * @memberof PostgresConnectionManager
15
- */
16
- close(): Promise<void>;
17
- }
@@ -1,68 +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
- getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
33
- getMemoriesByServerId(_params: {
34
- serverId: UUID;
35
- count?: number;
36
- }): Promise<Memory[]>;
37
- ensureAgentExists(agent: Partial<Agent>): Promise<Agent>;
38
- /**
39
- * Asynchronously runs the provided database operation while checking if the database is currently shutting down.
40
- * If the database is shutting down, a warning is logged and null is returned.
41
- *
42
- * @param {Function} operation - The database operation to be performed.
43
- * @returns {Promise<T>} A promise that resolves with the result of the database operation.
44
- */
45
- protected withDatabase<T>(operation: () => Promise<T>): Promise<T>;
46
- /**
47
- * Asynchronously initializes the database by running migrations.
48
- *
49
- * @returns {Promise<void>} A Promise that resolves when the database initialization is complete.
50
- */
51
- init(): Promise<void>;
52
- /**
53
- * Checks if the database connection is ready and active.
54
- * For PGLite, this checks if the client is not in a shutting down state.
55
- * @returns {Promise<boolean>} A Promise that resolves to true if the connection is healthy.
56
- */
57
- isReady(): Promise<boolean>;
58
- /**
59
- * Asynchronously closes the database.
60
- */
61
- close(): Promise<void>;
62
- /**
63
- * Asynchronously retrieves the connection from the client.
64
- *
65
- * @returns {Promise<PGlite>} A Promise that resolves with the connection.
66
- */
67
- getConnection(): Promise<import("@electric-sql/pglite").PGlite>;
68
- }
@@ -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,43 +0,0 @@
1
- import { type IDatabaseAdapter } from '@elizaos/core';
2
- /**
3
- * PostgreSQL Row-Level Security (RLS) for Multi-Tenant Isolation
4
- *
5
- * REQUIREMENT:
6
- * - RLS policies DO NOT apply to PostgreSQL superuser accounts.
7
- * - Use a REGULAR (non-superuser) database user
8
- * - Grant only necessary permissions (CREATE, SELECT, INSERT, UPDATE, DELETE)
9
- * - NEVER use the 'postgres' superuser or any superuser account
10
- *
11
- * Superusers bypass ALL RLS policies by design, which would completely
12
- * defeat the multi-tenant isolation mechanism.
13
- */
14
- /**
15
- * Install PostgreSQL functions required for RLS
16
- * These are stored procedures that must be created with raw SQL
17
- */
18
- export declare function installRLSFunctions(adapter: IDatabaseAdapter): Promise<void>;
19
- /**
20
- * Get or create RLS owner using Drizzle ORM
21
- */
22
- export declare function getOrCreateRlsOwner(adapter: IDatabaseAdapter, ownerId: string): Promise<string>;
23
- /**
24
- * Set RLS context on PostgreSQL connection pool
25
- * This function validates that the owner exists and has correct UUID format
26
- */
27
- export declare function setOwnerContext(adapter: IDatabaseAdapter, ownerId: string): Promise<void>;
28
- /**
29
- * Assign agent to owner using Drizzle ORM
30
- */
31
- export declare function assignAgentToOwner(adapter: IDatabaseAdapter, agentId: string, ownerId: string): Promise<void>;
32
- /**
33
- * Apply RLS to all tables by calling PostgreSQL function
34
- */
35
- export declare function applyRLSToNewTables(adapter: IDatabaseAdapter): Promise<void>;
36
- /**
37
- * Disable RLS globally
38
- * SIMPLE APPROACH:
39
- * - Disables RLS for ALL servers/owners
40
- * - Keeps owner_id columns and data intact
41
- * - Use only in development or when migrating to single-server mode
42
- */
43
- export declare function uninstallRLS(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,6 +0,0 @@
1
- import type { DrizzleDB } from './types';
2
- export declare class ExtensionManager {
3
- private db;
4
- constructor(db: DrizzleDB);
5
- installRequiredExtensions(extensions: string[]): Promise<void>;
6
- }
@@ -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
- }