/** * Root of `migration:up`'s per-version run-cache — a workspace-root-relative * directory. The CLI's `runModuleScripts` resolves it to a per-module * subdirectory (`var/cache/migrations//`) and passes that to the * module's `up`/`down` via `--cache-dir`, which write one JSON file per applied * migration version. Namespacing by module keeps two modules' * identically-versioned migrations from colliding on the same cache file. */ declare const MIGRATIONS_CACHE_DIR: string; import { SQL } from "bun"; declare const createMigrationTable: (sql: SQL, tableName: string) => Promise; import { EContainerScope } from "@talosjs/container"; import { SQL as SQL2, TransactionSQL } from "bun"; type MigrationClassType = new (...args: any[]) => IMigration; interface IMigration { up: (tx: TransactionSQL, sql: SQL2) => Promise; down: (tx: TransactionSQL, sql: SQL2) => Promise; getVersion: () => string; getDependencies: () => Promise | MigrationClassType[]; } /** * The connection a migration run borrows from an application database. * * `getSource()` builds it; `initialize()` opens the pool and `client` is the Bun SQL handle the * statements run on. Postgres and SQLite data sources both satisfy this. */ interface IMigrationDataSource { readonly options: { readonly type: string; readonly url?: string; readonly database?: string; }; isInitialized: boolean; readonly client: SQL2; initialize: () => Promise; destroy: () => Promise; } /** An application database, such as `MainDatabase`, that can open the connection migrations run against. */ interface IMigrationDatabase { getSource: (name?: string) => IMigrationDataSource; } /** What `up` and `down` need to reach the database they change. */ type MigrationConfigType = { database: IMigrationDatabase; /** Forwarded to `database.getSource()` when that database takes a connection name or file path. */ name?: string; tableName?: string; cacheDir?: string; }; type MigrationDownConfigType = MigrationConfigType & { version?: string; }; declare const decorator: { migration: (scope?: EContainerScope) => (target: MigrationClassType) => void; }; declare const down: (config: MigrationDownConfigType) => Promise; /** * Generates a migration version based on the current timestamp. * * Format: YYYYMMDDHHMMSSMMM * - YYYY: 4-digit year (e.g., 2025) * - MM: 2-digit month (01-12) * - DD: 2-digit day (01-31) * - HH: 2-digit hour in 24-hour format (00-23) * - MM: 2-digit minutes (00-59) * - SS: 2-digit seconds (00-59) * - MMM: 3-digit milliseconds (000-999) * * @returns {string} A migration version string (e.g., "20250630210755123") * * @example * const version = generateMigrationVersion(); * console.log(version); // "20250630210755123" */ declare const generateMigrationVersion: () => string; /** * Every registered migration, ordered by version and shifted so a migration * always comes after the ones it declares in `getDependencies()`. * * Dependencies declare *ordering*, not extra work: a dependency is itself a * registered migration that the runner applies exactly once. Versions are * timestamps and you can only depend on a migration that already exists, so * ascending version already places a dependency first — the pass below makes * that guarantee explicit rather than implied. * * A `getDependencies()` that resolves asynchronously keeps the version order * alone, so callers still get a plain array instead of a promise. */ declare const getMigrations: () => IMigration[]; /** * Per-migration (per-version) run cache for `migration:up`. * * The database `migrations` table stays the source of truth for what has been * applied; this cache is only a fast path. It lets `up` skip re-checking — and, * when every migration is already recorded, skip opening a database connection * altogether — for migrations whose code is unchanged since their last * successful apply. One JSON file per version lives under * `var/cache/migrations/`, so editing a single migration invalidates only that * migration's entry (unlike a per-module cache, which any change would drop). * * The fingerprint includes the target database identity and table name, so pointing * at a different database is always a miss. Like any cache decoupled from live * database state it can go stale if the database is reset out of band — `--drop` * and `--no-cache` bypass it for that reason, and `migration:down` deletes the * entry it rolls back. */ declare const MIGRATION_CACHE_VERSION = 1; type MigrationCacheEntryType = { version: number; id: string; hash: string; appliedAt: string; }; /** Directory holding one cache file per applied migration version. */ declare const migrationCacheDir: (rootDir?: string) => string; /** * Fingerprint a migration: its version and the source of its `up`/`down` * methods, scoped to the target database. Any change to the migration's code (or * to the database it targets) yields a new hash and therefore a cache miss. * `database` is that target's identity: its URL, or the dialect plus name or file. */ declare const computeMigrationHash: (migration: IMigration, tableName: string, database?: string) => string; /** * True when version `id` has a cache entry matching `hash` — i.e. it was applied * successfully and its code is unchanged. Reads never throw: a missing or * unreadable entry is simply a miss. */ declare const isMigrationCached: (dir: string, id: string, hash: string) => Promise; /** Record a successful apply so version `id` can be skipped next time. Never throws. */ declare const writeMigrationCache: (dir: string, id: string, hash: string) => Promise; /** Drop version `id`'s cache entry (e.g. after a rollback) so the next `up` re-applies it. Never throws. */ declare const deleteMigrationCache: (dir: string, id: string) => Promise; declare const migrationCreate: (config?: { migrationsDir?: string; }) => Promise<{ migrationPath: string; }>; declare const migrationTestCreate: (config: { name: string; testsDir: string; module?: string; }) => Promise; declare const up: (config: MigrationConfigType) => Promise; export { IMigration, IMigrationDataSource, IMigrationDatabase, MIGRATIONS_CACHE_DIR, MIGRATION_CACHE_VERSION, MigrationCacheEntryType, MigrationClassType, MigrationConfigType, MigrationDownConfigType, computeMigrationHash, createMigrationTable, decorator, deleteMigrationCache, down, generateMigrationVersion, getMigrations, isMigrationCached, migrationCacheDir, migrationCreate, migrationTestCreate, up, writeMigrationCache };