/** * SQL File-Based Migration Runner * * Purpose: Manages database schema migrations using SQL files * * Features: * - Executes SQL migration files in order * - Tracks migration versions in database * - Supports both TypeScript and SQL file migrations * - Prevents concurrent migrations with locks * - Provides rollback support (future enhancement) * - Better error handling and logging * * Migration File Naming Convention: * - {version}_{description}.sql (e.g., 0001_create_events_table.sql) * - Version numbers must be sequential * - Files are executed in numeric order * * Implementation: * - 2025-11-02: Initial implementation replacing inline TypeScript migrations */ import type { Database } from 'sqlite3'; export interface MigrationContext { db: Database; migrationsDir: string; } export interface MigrationFile { version: number; name: string; filePath: string; } interface MigrationRecord { version: number; name: string; applied_at: string; } /** * Get current schema version from database */ export declare function getCurrentVersion(db: Database): Promise; /** * Set schema version in database */ export declare function setVersion(db: Database, version: number): Promise; /** * Create migration tracking table if it doesn't exist * This provides better migration history than just PRAGMA user_version */ export declare function ensureMigrationTable(db: Database): Promise; /** * Get list of applied migrations from tracking table */ export declare function getAppliedMigrations(db: Database): Promise; /** * Record a migration in the tracking table */ export declare function recordMigration(db: Database, version: number, name: string): Promise; /** * Discover all SQL migration files in the migrations directory */ export declare function discoverMigrations(migrationsDir: string): MigrationFile[]; /** * Read and parse SQL migration file */ export declare function readMigrationFile(filePath: string): string; /** * Execute a single migration file */ export declare function executeMigration(db: Database, migration: MigrationFile): Promise; /** * Check if migrations are needed */ export declare function needsMigration(db: Database, migrationsDir: string): Promise; /** * Run all pending migrations */ export declare function runMigrations(ctx: MigrationContext): Promise; /** * Get migration status and history */ export declare function getMigrationStatus(ctx: MigrationContext): Promise<{ currentVersion: number; availableMigrations: MigrationFile[]; appliedMigrations: MigrationRecord[]; pendingMigrations: MigrationFile[]; }>; /** * Validate migration file sequence * Ensures no gaps or duplicates in version numbers */ export declare function validateMigrationSequence(migrations: MigrationFile[]): { isValid: boolean; errors: string[]; }; export {};