import { Attribute, EntityDict, GeneralEntityShape, Index, StorageDesc, StorageSchema } from 'oak-domain/lib/types'; export type MigrationEntityDict = EntityDict; export type MigrationEntityKey = keyof MigrationEntityDict & string; export type MigrationSchema = StorageSchema; export type MigrationTableDef = StorageDesc; export type MigrationIndex = Index; export interface MigrationIndexMetadata { __originName?: string; __originNames?: string[]; } export type MigrationIndexWithOrigin = MigrationIndex & MigrationIndexMetadata; export type MigrationWarningLevel = 'info' | 'warning'; export type MigrationWarningCode = 'rename-candidate' | 'manual-column-change' | 'manual-index-change' | 'manual-enum-change' | 'manual-constraint-change' | 'large-table-index-change'; export interface MigrationWarning { code: MigrationWarningCode; level: MigrationWarningLevel; message: string; table?: string; column?: string; sql?: string[]; } export interface RenameCandidate { table: string; from: string; to: string; reason: string; sql: string[]; } export interface ForeignKeyDef { name: string; column: string; refTable: string; refColumn: string; onDelete: 'cascade' | 'set null' | 'no action'; } export interface TableStats { rowCount?: number; approximate?: boolean; } export interface SchemaInspectionResult { schema: MigrationSchema; tableStats: Record; } export interface MigrationPlanningOptions { currentTableStats?: Record; largeTableRowThreshold?: number; compareForeignKeys?: boolean; } export interface IndexPlanContext { isNewTable: boolean; tableStats?: TableStats; largeTableRowThreshold: number; } export interface MigrationPlanSummary { newTables: number; removedTables: number; addedColumns: number; removedColumns: number; changedColumns: number; addedIndexes: number; removedIndexes: number; changedIndexes: number; addedForeignKeys: number; removedForeignKeys: number; changedForeignKeys: number; manualActions: number; onlineActions: number; largeTableIndexes: number; } export type MigrationSqlCategory = 'prepareSql' | 'forwardSql' | 'onlineSql' | 'manualSql' | 'backwardSql'; export interface MigrationSqlByCategory { prepareSql: string[]; forwardSql: string[]; onlineSql: string[]; manualSql: string[]; backwardSql: string[]; } export interface MigrationTableColumnAddition { name: string; categories: MigrationSqlCategory[]; reason?: string; definition: AttributeSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableColumnRemoval { name: string; categories: MigrationSqlCategory[]; definition: AttributeSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableColumnChange { name: string; categories: MigrationSqlCategory[]; reason?: string; before: AttributeSnapshot; after: AttributeSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableColumnRename { from: string; to: string; categories: MigrationSqlCategory[]; reason: string; before: AttributeSnapshot; after: AttributeSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableIndexAddition { name: string; categories: MigrationSqlCategory[]; definition: IndexSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableIndexRemoval { name: string; categories: MigrationSqlCategory[]; definition: IndexSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableIndexChange { name: string; categories: MigrationSqlCategory[]; before: IndexSnapshot; after: IndexSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableIndexRename { from: string; to: string; categories: MigrationSqlCategory[]; before: IndexSnapshot; after: IndexSnapshot; sql: MigrationSqlByCategory; } export interface MigrationTableForeignKeyAddition { name: string; categories: MigrationSqlCategory[]; definition: ForeignKeyDef; sql: MigrationSqlByCategory; } export interface MigrationTableForeignKeyRemoval { name: string; categories: MigrationSqlCategory[]; definition: ForeignKeyDef; sql: MigrationSqlByCategory; } export interface MigrationTableForeignKeyChange { name: string; categories: MigrationSqlCategory[]; before?: ForeignKeyDef; after?: ForeignKeyDef; sql: MigrationSqlByCategory; } export interface MigrationTableChange { entity: string; table: string; lifecycle: 'create' | 'alter' | 'drop'; summary: MigrationPlanSummary; sql: MigrationSqlByCategory; columns: { added: MigrationTableColumnAddition[]; removed: MigrationTableColumnRemoval[]; changed: MigrationTableColumnChange[]; renamed: MigrationTableColumnRename[]; }; indexes: { added: MigrationTableIndexAddition[]; removed: MigrationTableIndexRemoval[]; changed: MigrationTableIndexChange[]; renamed: MigrationTableIndexRename[]; }; foreignKeys: { added: MigrationTableForeignKeyAddition[]; removed: MigrationTableForeignKeyRemoval[]; changed: MigrationTableForeignKeyChange[]; }; warnings: MigrationWarning[]; renameCandidates: RenameCandidate[]; } export interface MigrationPlan { currentSchema: MigrationSchema; targetSchema: MigrationSchema; prepareSql: string[]; forwardSql: string[]; onlineSql: string[]; manualSql: string[]; backwardSql: string[]; warnings: MigrationWarning[]; renameCandidates: RenameCandidate[]; summary: MigrationPlanSummary; tableChanges: MigrationTableChange[]; } export type Plan = MigrationPlan; export interface MigrationChangePlan { prepareSql?: string[]; forwardSql?: string[]; deferredForwardSql?: string[]; onlineSql?: string[]; manualSql?: string[]; backwardSql?: string[]; warnings?: MigrationWarning[]; renameCandidates?: RenameCandidate[]; summary?: Partial; } export interface AttributeSnapshot { type: string; params?: Record; enumeration?: string[]; ref?: string | string[]; onRefDelete?: 'delete' | 'setNull' | 'ignore'; default?: string | number | boolean; notNull: boolean; unique: boolean; sequence: boolean; } export interface IndexSnapshot { name: string; attributes: Array<{ name: string; direction?: 'ASC' | 'DESC'; size?: number; }>; config: { unique: boolean; type: 'btree' | 'hash' | 'spatial' | 'fulltext'; parser?: string; tsConfig?: string | string[]; chineseParser?: string; include?: string[]; }; } export interface AttributeChangeClassification { mode: 'none' | 'forward' | 'manual'; reason?: string; enumAppendOnly?: true; } export interface SchemaMigrationAdapter { readonly dialect: 'mysql' | 'postgresql' | 'sqlite'; normalizeIdentifier(name: string): string; getTableName(table: string, tableDef?: { storageName?: string; }): string; buildPrepareSql(currentSchema: MigrationSchema, targetSchema: MigrationSchema): string[]; buildNewTablePlan(table: string, tableDef: MigrationTableDef): MigrationChangePlan; buildDropTablePlan(tableName: string): MigrationChangePlan; buildColumnPlan(tableName: string, column: string, oldAttr: Attribute | undefined, newAttr: Attribute | undefined, classification: AttributeChangeClassification): MigrationChangePlan; buildIndexPlan(tableName: string, table: string, oldIndex: MigrationIndexWithOrigin | undefined, newIndex: MigrationIndexWithOrigin | undefined, context: IndexPlanContext): MigrationChangePlan; buildRenameIndexPlan(tableName: string, table: string, oldIndex: MigrationIndexWithOrigin, newIndex: MigrationIndexWithOrigin, context: IndexPlanContext): MigrationChangePlan; buildForeignKeyPlan(tableName: string, oldForeignKey: ForeignKeyDef | undefined, newForeignKey: ForeignKeyDef | undefined, isNewTable: boolean): MigrationChangePlan; getForeignKeys(table: string, tableDef: MigrationTableDef, fullSchema: MigrationSchema): Record; }