Merge pull request #33 from builderz-labs/fix/db-foreign-keys-indexes

Fix SQLite foreign keys and add missing indexes
This commit is contained in:
nyk 2026-02-27 20:08:14 +07:00 committed by GitHub
commit 0e65f97253
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View File

@ -106,7 +106,7 @@ mission-control/
│ ├── lib/
│ │ ├── auth.ts # Session + API key auth, RBAC
│ │ ├── db.ts # SQLite (better-sqlite3, WAL mode)
│ │ ├── migrations.ts # 14 schema migrations
│ │ ├── migrations.ts # 15 schema migrations
│ │ ├── scheduler.ts # Background task scheduler
│ │ ├── webhooks.ts # Outbound webhook delivery
│ │ └── websocket.ts # Gateway WebSocket client

View File

@ -23,6 +23,7 @@ export function getDatabase(): Database.Database {
db.pragma('journal_mode = WAL');
db.pragma('synchronous = NORMAL');
db.pragma('cache_size = 1000');
db.pragma('foreign_keys = ON');
// Initialize schema if needed
initializeSchema();

View File

@ -424,6 +424,18 @@ const migrations: Migration[] = [
db.exec(`CREATE INDEX IF NOT EXISTS idx_users_provider ON users(provider)`)
db.exec(`CREATE INDEX IF NOT EXISTS idx_users_email ON users(email)`)
}
},
{
id: '015_missing_indexes',
up: (db) => {
db.exec(`
CREATE INDEX IF NOT EXISTS idx_notifications_read_at ON notifications(read_at);
CREATE INDEX IF NOT EXISTS idx_notifications_recipient_read ON notifications(recipient, read_at);
CREATE INDEX IF NOT EXISTS idx_activities_actor ON activities(actor);
CREATE INDEX IF NOT EXISTS idx_activities_entity ON activities(entity_type, entity_id);
CREATE INDEX IF NOT EXISTS idx_messages_read_at ON messages(read_at);
`)
}
}
]