import { DatabaseContext } from '../entity/db-context'; import { MigrationConfig } from './migration.interface'; /** * Generates migration scaffold files from schema differences. * * The scaffold generator: * - Uses DbSchemaManager.analyze() to detect schema differences * - Generates TypeScript migration files with up() and down() methods * - Creates SQL statements for each detected change * * @example * ```typescript * const scaffold = new MigrationScaffold(db, { * migrationsDirectory: './migrations', * }); * * // Generate migration from schema diff * const result = await scaffold.scaffold('../schema/appDatabase'); * console.log(`Created: ${result.filename} with ${result.operations} operations`); * * // Generate empty migration template * const empty = await scaffold.scaffoldEmpty(); * ``` */ export declare class MigrationScaffold { private db; private config; private loader; constructor(db: DatabaseContext, config: MigrationConfig); /** * Generate SQL for a migration operation (UP direction). * Returns an array of statements for operations that need multiple queries. */ private generateUpSql; /** * Generate SQL for a migration operation (DOWN direction - reverse). */ private generateDownSql; /** * Build CREATE SEQUENCE SQL. */ private buildCreateSequenceSql; /** * Build CREATE TABLE SQL from schema. * Returns an array: CREATE TABLE IF NOT EXISTS with PK columns only, * followed by ADD COLUMN IF NOT EXISTS for each remaining column. */ private buildCreateTableSql; /** * Build ADD COLUMN SQL. */ private buildAddColumnSql; /** * Build ALTER COLUMN SQL statements. */ private buildAlterColumnSql; /** * Resolve the effective type from database column info. * Handles ARRAY and USER-DEFINED types by using udt_name. */ private resolveDbType; /** * Build the UP SQL for a create_index / recreate_index operation. * Returns [DROP IF EXISTS, CREATE] for idempotency, so a recreate replaces a * changed-signature index in place. Uses the shared builders so the generated * SQL is identical to the live auto-migrate path — including `USING ` * and per-column operator classes (which the previous scaffold omitted). */ private buildIndexUpSql; /** * Build CREATE FOREIGN KEY SQL. * Returns [DROP IF EXISTS, ADD CONSTRAINT] for idempotency. */ private buildCreateForeignKeySql; /** * Format a default value for SQL. */ private formatDefault; /** * Generate a migration file from schema differences. * * Compares the current database state to the DataContext model * and generates a migration file with the necessary SQL statements. * * @param contextImportPath - Optional import path for the DataContext class * @returns Information about the generated migration file * @throws Error if no schema differences are detected */ scaffold(contextImportPath?: string): Promise<{ filename: string; path: string; operations: number; }>; /** * Generate an empty migration file template. * * @param contextImportPath - Optional import path for the DataContext class * @returns Information about the generated migration file */ scaffoldEmpty(contextImportPath?: string): Promise<{ filename: string; path: string; }>; /** * Generate migration file content with SQL statements. */ private generateMigrationFile; /** * Generate an empty migration file template. */ private generateEmptyMigrationFile; } //# sourceMappingURL=migration-scaffold.d.ts.map