import type { InputMigrations, MigrationParams, RunnableMigration, UmzugStorage } from "umzug"; import type { SnapshotResult } from "./DatabaseConfig.js"; import { type FileBaseName, type SortedScripts } from "./script-generator.js"; /** * The resolveScript function type without the `this` binding. * Used when passing resolveScript as a standalone function parameter. */ type ResolveScriptFn = (params: MigrationParams & { path: string; }) => RunnableMigration; /** * The generateSnapshot function type without the `this` binding. * Used when passing generateSnapshot as a standalone function parameter. */ type GenerateSnapshotFn = (params: { env: string; scripts: Array<{ path: string; name: string; }>; }) => Promise; /** * Result of applying a snapshot - a discriminated union reflecting the mutually * exclusive outcomes: * - 'no-snapshot': No snapshot existed in the scripts directory * - 'ran-snapshot': The snapshot was run directly (fresh database) * - 'skipped-snapshot': The snapshot was skipped because some archived scripts * were already executed; missing archived scripts were run instead and then * the snapshot was marked as executed. */ type ApplySnapshotResult = { type: "no-snapshot"; } | { type: "ran-snapshot"; } | { type: "skipped-snapshot"; archivedScriptsRun: string[]; }; type ApplyScriptsResult = { /** What happened with the snapshot (if any) */ snapshot: ApplySnapshotResult; /** The configured Umzug migrations function (for use with Umzug) */ migrations: InputMigrations; }; type CreateSnapshotResult = { snapshotTimestamp: string; schemaFile: FileBaseName; seedFiles: FileBaseName[]; archivedScripts: FileBaseName[]; }; /** * Prepares script application with snapshot support. * * This function handles the logic of determining which scripts to run: * - If a snapshot exists and none of its archived scripts have been executed, run the snapshot directly * - If some archived scripts have been executed, run the missing ones from the archive and mark snapshot as executed * * After this function runs, the snapshot (if any) has been applied, * and the returned migrations function contains only non-snapshot scripts for Umzug to run. * * Returns the information needed to configure Umzug and track what was done. */ export declare function prepareScriptApplication(opts: { env: string; scriptsDirectory: string; snapshotArchivesDirectory: string; supportedScriptFormats: readonly string[]; storage: UmzugStorage; context: Context; resolveScript: ResolveScriptFn; /** All script file paths on disk (absolute paths), already sorted */ scriptFilePaths: readonly string[]; logger?: { log: (msg: string) => void; }; /** If specified, only apply snapshots and migrations up to this script name */ upTo?: FileBaseName; }): Promise>; /** * Creates snapshot files for all environments and archives the original scripts. */ export declare function createSnapshotAndArchiveCoveredScripts(opts: { scriptsDirectory: string; snapshotArchivesDirectory: string; supportedScriptFormats: SortedScripts; supportedEnvironments: readonly [string, ...string[]]; generateSnapshot: GenerateSnapshotFn; /** All script file paths on disk (absolute paths), already sorted */ scriptFilePaths: readonly string[]; /** Only include scripts up to this name (lexicographically) */ upTo?: string; logger?: { log: (msg: string) => void; }; }): Promise; export {}; //# sourceMappingURL=snapshot-operations.d.ts.map