/**
 * Migration: 024 - feedback_event (memory_id, created_at) composite index
 * Version: 24.0
 */
export class FeedbackEventMemoryCreatedAtIndexMigration {
    version = '24.0';
    name = 'feedback-event-memory-created-at-index';
    description = 'Composite index on feedback_event(memory_id, created_at) for sliding-window net score 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, 'feedback_event')) {
            return;
        }
        db.exec('CREATE INDEX IF NOT EXISTS idx_feedback_memory_created_at ON feedback_event(memory_id, created_at)');
    }
    async down(db) {
        db.exec('DROP INDEX IF EXISTS idx_feedback_memory_created_at');
        if (this.tableExists(db, 'memento_schema_version')) {
            db.prepare('DELETE FROM memento_schema_version WHERE version = ?').run('24.0');
        }
    }
    async validateAfter(db) {
        if (!this.tableExists(db, 'feedback_event')) {
            return;
        }
        if (!this.indexExists(db, 'idx_feedback_memory_created_at')) {
            throw new Error('idx_feedback_memory_created_at index was not created');
        }
    }
}
export default FeedbackEventMemoryCreatedAtIndexMigration;
//# sourceMappingURL=024-feedback-event-memory-created-at-index.js.map