CREATE TABLE migration_history (
    migration_id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
    migration_version INTEGER NOT NULL,
    migration_name TEXT NOT NULL,
    executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    duration_ms INTEGER NOT NULL,
    status TEXT NOT NULL CHECK (status IN ('success', 'failed', 'reverted')),
    error_message TEXT
);

CREATE INDEX idx_migration_history_name ON migration_history(migration_name);
CREATE INDEX idx_migration_history_executed_at ON migration_history(executed_at);
