UNPKG

@iarayan/ch-orm

Version:

A Developer-First ClickHouse ORM with Powerful CLI Tools

125 lines 4.13 kB
import { Connection } from "../connection/Connection"; import { Migration } from "./Migration"; import { MigrationRecord } from "./models/MigrationRecord"; /** * MigrationRunner class for managing migration execution * Handles applying and rolling back migrations */ export declare class MigrationRunner { /** * Connection to the database */ private connection; /** * Schema instance for database operations */ private schema; /** * Name of the migrations table */ private migrationsTable; /** * Array of migrations to be applied or rolled back */ private migrations; /** * Create a new MigrationRunner instance * @param connection - ClickHouse connection */ constructor(connection: Connection); /** * Set the name of the migrations table * @param tableName - Migrations table name * @returns MigrationRunner instance for chaining */ setMigrationsTable(tableName: string): this; /** * Add a migration to the runner * @param migration - Migration instance * @returns MigrationRunner instance for chaining */ add(migration: Migration): this; /** * Add multiple migrations to the runner * @param migrations - Array of migration instances * @returns MigrationRunner instance for chaining */ addMultiple(migrations: Migration[]): this; /** * Set the migrations for the runner * @param migrations - Array of migration instances * @returns MigrationRunner instance for chaining */ setMigrations(migrations: Migration[]): this; /** * Ensure the migrations table exists * @returns Promise that resolves when the migrations table is created (if needed) */ private ensureMigrationsTable; /** * Get all migration records from the database * @returns Promise that resolves to array of migration records */ getMigrationRecords(): Promise<MigrationRecord[]>; /** * Get the last batch number from the migration records * @returns Promise that resolves to the last batch number or 0 if no migrations have been run */ private getLastBatchNumber; /** * Save a migration record to the database * @param migration - Migration instance * @param batch - Batch number * @param executionTime - Execution time in seconds * @returns Promise that resolves when the record is saved */ private saveMigrationRecord; /** * Delete a migration record from the database * @param migration - Migration instance * @returns Promise that resolves when the record is deleted */ private deleteMigrationRecord; /** * Run pending migrations * @returns Promise that resolves to number of migrations applied */ run(): Promise<number>; /** * Rollback the last batch of migrations * @returns Promise that resolves to number of migrations rolled back */ rollback(): Promise<number>; /** * Reset the database by rolling back all migrations * @returns Promise that resolves to number of migrations rolled back */ reset(): Promise<number>; /** * Refresh the database by rolling back all migrations and then running them again * @returns Promise that resolves to number of migrations applied */ refresh(): Promise<number>; /** * Get array of pending migrations * @returns Promise that resolves to array of pending migration names */ getPendingMigrations(): Promise<string[]>; /** * Get array of all migration names * @returns Array of all migration names */ getMigrationNames(): string[]; /** * Get the underlying connection instance * @returns Connection instance */ getConnection(): Connection; /** * Create the migrations table if it doesn't exist * This is used to track which migrations have been applied * @returns Promise that resolves when the table is created */ private createMigrationsTable; } //# sourceMappingURL=MigrationRunner.d.ts.map