/**
 * Migration: 029 — telemetry_events (event_type, created_at) composite index
 * Version: 29.0
 */
export class TelemetryEventsEventTypeCreatedAtIndexMigration {
    version = '29.0';
    name = 'telemetry-events-event-type-created-at-index';
    description = 'Composite index on telemetry_events(event_type, created_at) for time-scoped event-type queries';
    tableExists(db, tableName) {
        const result = db
            .prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name=?`)
            .get(tableName);
        return !!result;
    }
    indexExists(db, indexName) {
        const row = db
            .prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`)
            .get(indexName);
        return !!row;
    }
    async validateBefore(_db) { }
    async up(db) {
        if (!this.tableExists(db, 'telemetry_events')) {
            return;
        }
        db.exec('CREATE INDEX IF NOT EXISTS idx_te_event_type_created_at ON telemetry_events(event_type, created_at)');
    }
    async down(db) {
        db.exec('DROP INDEX IF EXISTS idx_te_event_type_created_at');
        if (this.tableExists(db, 'memento_schema_version')) {
            db.prepare('DELETE FROM memento_schema_version WHERE version = ?').run('29.0');
        }
    }
    async validateAfter(db) {
        if (!this.tableExists(db, 'telemetry_events')) {
            return;
        }
        if (!this.indexExists(db, 'idx_te_event_type_created_at')) {
            throw new Error('idx_te_event_type_created_at index was not created');
        }
    }
}
export default TelemetryEventsEventTypeCreatedAtIndexMigration;
//# sourceMappingURL=029-telemetry-events-event-type-created-at-index.js.map