import type { Database as NativeDatabase } from '@visorcraft/mongreldb/native.js'; import { KitDatabase, type SqlOptions } from './db.js'; import { type Schema } from './schema.js'; import type { TableSpec, ColumnSpec, IndexSpec, UniqueSpec, ForeignKeySpec } from './types.js'; import { type ProcedureSpec } from './procedure.js'; import { type TriggerSpec } from './trigger.js'; import { type ViewSpec, type VirtualTableSpec } from './external.js'; /** * A declarative migration operation. Mirrors the Rust * `mongreldb_kit_core::migrations::MigrationOp` enum. These describe *what* a * migration changes; the imperative `up()` callback performs the change. When * present on a migration they are folded into its content-aware checksum so * editing the op list is detected as schema drift. */ export type MigrationOp = { kind: 'createTable'; name: string; } | { kind: 'dropTable'; name: string; } | { kind: 'addColumn'; table: string; column: string; } | { kind: 'dropColumn'; table: string; column: string; } | { kind: 'alterColumn'; table: string; column: string; } | { kind: 'addIndex'; table: string; index: string; } | { kind: 'dropIndex'; table: string; index: string; } | { kind: 'addUnique'; table: string; constraint: string; } | { kind: 'dropUnique'; table: string; constraint: string; } | { kind: 'addForeignKey'; table: string; constraint: string; } | { kind: 'dropForeignKey'; table: string; constraint: string; } | { kind: 'addCheck'; table: string; constraint: string; } | { kind: 'dropCheck'; table: string; constraint: string; } | { kind: 'createProcedure'; name: string; procedure: ProcedureSpec; } | { kind: 'replaceProcedure'; name: string; procedure: ProcedureSpec; } | { kind: 'dropProcedure'; name: string; } | { kind: 'createTrigger'; name: string; trigger: TriggerSpec; } | { kind: 'replaceTrigger'; name: string; trigger: TriggerSpec; } | { kind: 'dropTrigger'; name: string; } | { kind: 'createVirtualTable'; table: VirtualTableSpec; } | { kind: 'dropVirtualTable'; name: string; } | { kind: 'createView'; name: string; view: ViewSpec; } | { kind: 'replaceView'; name: string; view: ViewSpec; } | { kind: 'dropView'; name: string; } | { kind: 'rawSql'; sql: string; }; export interface Migration { version: number; name: string; /** * Optional declarative description of the migration's operations. Including * it makes the migration checksum content-aware so a later edit to the ops * is rejected as drift. When omitted the checksum covers `version`/`name` * with an empty op list. */ ops?: MigrationOp[]; up: (ctx: MigrationContext) => Promise | void; } export interface MigrationContext { kit: KitDatabase; db: NativeDatabase; ensureTable: (table: TableSpec) => Promise | void; addColumn: (tableName: string, column: ColumnSpec) => Promise | void; dropColumn: (tableName: string, columnName: string) => Promise | void; alterColumn: (tableName: string, columnName: string, newColumn: ColumnSpec) => Promise | void; addIndex: (tableName: string, index: IndexSpec) => Promise | void; dropIndex: (tableName: string, indexName: string) => Promise | void; createTrigger: (trigger: TriggerSpec) => Promise | void; replaceTrigger: (trigger: TriggerSpec) => Promise | void; dropTrigger: (name: string) => Promise | void; createVirtualTable: (table: VirtualTableSpec) => Promise | void; dropVirtualTable: (name: string) => Promise | void; createView: (view: ViewSpec) => Promise | void; replaceView: (view: ViewSpec) => Promise | void; dropView: (name: string) => Promise | void; sql: (sql: string, options?: SqlOptions) => Promise | unknown[]; } export interface MigrationOptions { sql?: SqlOptions; } /** * The canonical content string a migration's checksum is computed over. Shape: * `{"version":,"name":,"ops":[,...]}` with no insignificant * whitespace, byte-identical to the Rust kit's `canonical_content`. */ export declare function migrationContent(migration: Migration): string; /** * Content-aware SHA-256 checksum for a migration. Covers the version, name, and * ordered op list via {@link migrationContent}; the same logical migration * produces the identical checksum in TypeScript, Rust, and Python. */ export declare function migrationChecksum(migration: Migration): string; export declare function migrateSync(kit: KitDatabase, schema: Schema, migrations: Migration[]): void; export declare function migrate(kit: KitDatabase, schema: Schema, migrations: Migration[], options?: MigrationOptions): Promise; export declare function createTable(kit: KitDatabase, table: TableSpec): Promise; export declare function createVirtualTable(kit: KitDatabase, table: VirtualTableSpec, options?: SqlOptions): Promise; export declare function dropVirtualTable(kit: KitDatabase, name: string, options?: SqlOptions): Promise; /** Create (or replace — the engine overwrites) a SQL view. Async-only: runs * `CREATE VIEW` through the kit's SQL surface. */ export declare function createView(kit: KitDatabase, v: ViewSpec, options?: SqlOptions): Promise; /** Replace a SQL view (re-issues `CREATE VIEW`; the engine overwrites). */ export declare function replaceView(kit: KitDatabase, v: ViewSpec, options?: SqlOptions): Promise; /** Drop a SQL view by name. Idempotent (`DROP VIEW IF EXISTS`). */ export declare function dropView(kit: KitDatabase, name: string, options?: SqlOptions): Promise; /** * Drop `tableName` and remove every unique-key and row guard it owned. The * application row data and its guards are gone after this; the schema catalog is * re-persisted by the migration runner once all ops complete. */ export declare function dropTable(kit: KitDatabase, tableName: string): Promise; export declare function addColumn(kit: KitDatabase, tableName: string, column: ColumnSpec): Promise; /** * Change the declared type or constraints of an existing column in place. * * Kit keeps application-only changes metadata-local when the old and new * storage types map to the same engine {@link ColumnType}. Native schema * changes (rename, storage type, nullability, primary-key/sequence flags) are * delegated to MongrelDB's native ALTER COLUMN validation. */ export declare function alterColumn(kit: KitDatabase, tableName: string, columnName: string, newColumn: ColumnSpec): Promise; export declare function addIndex(kit: KitDatabase, tableName: string, index: IndexSpec): Promise; /** Replace one non-unique single-column index through the hidden-generation job path. */ export declare function replaceIndex(kit: KitDatabase, tableName: string, expectedOldName: string, replacement: IndexSpec): Promise; export declare function dropIndex(kit: KitDatabase, tableName: string, indexName: string): Promise; export declare function dropColumn(kit: KitDatabase, tableName: string, columnName: string): Promise; export declare function addUnique(kit: KitDatabase, tableName: string, unique: UniqueSpec): Promise; /** * Add a foreign key and backfill parent `__kit_row_guards` (PLAN "Migrations"). * Each existing child row with a non-null FK must reference an existing parent; * a missing parent rejects the migration. The referenced parent's row guard is * touched so a later concurrent parent delete conflicts. The FK is added to the * in-memory table so subsequent writes enforce it. */ export declare function addForeignKey(kit: KitDatabase, tableName: string, fk: ForeignKeySpec): Promise; //# sourceMappingURL=migrate.d.ts.map