Rollback & expand
Rollback
Section titled “Rollback”import { ensureSnapshotsTable, saveSnapshot, getLatestSnapshot, listSnapshots, deleteSnapshot, computeRollback, runDown,} from '@smplcty/schema-flow';
// Execute rollbackconst result = await runDown(config, logger);
// Manual snapshot managementawait withClient(connectionString, async (client) => { await ensureSnapshotsTable(client);
const snapshots = await listSnapshots(client); const latest = await getLatestSnapshot(client);
if (latest) { const reverseOps = computeRollback(latest); // reverseOps: Operation[] }
await deleteSnapshot(client, snapshotId);});interface MigrationSnapshot { id: string; operations: Operation[]; createdAt: Date;}
interface RollbackResult { success: boolean; operationsExecuted: number; errors: string[];}Expand/contract
Section titled “Expand/contract”import { ensureExpandStateTable, planExpandColumn, runBackfill, runContract, getExpandStatus,} from '@smplcty/schema-flow';
await withClient(connectionString, async (client) => { await ensureExpandStateTable(client);
// Check status const status = await getExpandStatus(client); // status: ExpandState[]
// Run backfill const backfillResult = await runBackfill({ connectionString, table: 'users', column: 'email_lower', batchSize: 1000, logger, });
// Complete contract const contractResult = await runContract({ connectionString, table: 'users', column: 'email', allowDestructive: true, logger, });});interface ExpandState { table: string; newColumn: string; oldColumn: string; status: string;}
interface BackfillOptions { connectionString: string; table: string; column: string; batchSize?: number; logger: Logger;}
interface BackfillResult { rowsUpdated: number;}
interface ContractOptions { connectionString: string; table: string; column: string; allowDestructive: boolean; logger: Logger;}
interface ContractResult { success: boolean;}