@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.
- package/dist/browser/index.browser.js +1907 -436
- package/dist/browser/index.browser.js.map +26 -23
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.node.js +1436 -662
- package/dist/node/index.node.js.map +33 -31
- package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
- package/package.json +17 -14
- package/dist/browser/base.d.ts +0 -926
- package/dist/browser/index.browser.d.ts +0 -11
- package/dist/browser/migration-service.d.ts +0 -43
- package/dist/browser/pglite/adapter.d.ts +0 -68
- package/dist/browser/pglite/manager.d.ts +0 -21
- 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/owners.d.ts +0 -63
- 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/serverAgent.d.ts +0 -41
- 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 -926
- package/dist/browser/src/index.browser.d.ts +0 -11
- package/dist/browser/src/migration-service.d.ts +0 -43
- package/dist/browser/src/pglite/adapter.d.ts +0 -68
- package/dist/browser/src/pglite/manager.d.ts +0 -21
- 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/owners.d.ts +0 -63
- 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/serverAgent.d.ts +0 -41
- 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 -926
- 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/pg/adapter.d.ts +0 -69
- package/dist/node/src/pg/manager.d.ts +0 -17
- package/dist/node/src/pglite/adapter.d.ts +0 -68
- package/dist/node/src/pglite/manager.d.ts +0 -21
- package/dist/node/src/rls.d.ts +0 -43
- 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/owners.d.ts +0 -63
- 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/serverAgent.d.ts +0 -41
- 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,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,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
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
-
import type { PgliteDatabase } from 'drizzle-orm/pglite';
|
|
3
|
-
export type DrizzleDB = NodePgDatabase | PgliteDatabase;
|
|
4
|
-
export interface Journal {
|
|
5
|
-
version: string;
|
|
6
|
-
dialect: string;
|
|
7
|
-
entries: JournalEntry[];
|
|
8
|
-
}
|
|
9
|
-
export interface JournalEntry {
|
|
10
|
-
idx: number;
|
|
11
|
-
version: string;
|
|
12
|
-
when: number;
|
|
13
|
-
tag: string;
|
|
14
|
-
breakpoints: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface MigrationMeta {
|
|
17
|
-
sql: string[];
|
|
18
|
-
folderMillis: number;
|
|
19
|
-
hash: string;
|
|
20
|
-
bps: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface SchemaSnapshot {
|
|
23
|
-
version: string;
|
|
24
|
-
dialect: string;
|
|
25
|
-
tables: any;
|
|
26
|
-
schemas: any;
|
|
27
|
-
enums?: any;
|
|
28
|
-
_meta: {
|
|
29
|
-
schemas: any;
|
|
30
|
-
tables: any;
|
|
31
|
-
columns: any;
|
|
32
|
-
};
|
|
33
|
-
internal?: any;
|
|
34
|
-
}
|
|
35
|
-
export interface MigrationOptions {
|
|
36
|
-
migrationsTable?: string;
|
|
37
|
-
migrationsSchema?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface RuntimeMigrationOptions {
|
|
40
|
-
/** Run without executing SQL statements */
|
|
41
|
-
dryRun?: boolean;
|
|
42
|
-
/** Log detailed information about the migration */
|
|
43
|
-
verbose?: boolean;
|
|
44
|
-
/** Force migration even in production with destructive changes */
|
|
45
|
-
force?: boolean;
|
|
46
|
-
/** Allow operations that will cause data loss (tables/columns being dropped) */
|
|
47
|
-
allowDataLoss?: boolean;
|
|
48
|
-
}
|