Skip to content

Commit 0e65f97

Browse files
authored
Merge pull request #33 from builderz-labs/fix/db-foreign-keys-indexes
Fix SQLite foreign keys and add missing indexes
2 parents 3218cfd + b5766b0 commit 0e65f97

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ mission-control/
106106
│ ├── lib/
107107
│ │ ├── auth.ts # Session + API key auth, RBAC
108108
│ │ ├── db.ts # SQLite (better-sqlite3, WAL mode)
109-
│ │ ├── migrations.ts # 14 schema migrations
109+
│ │ ├── migrations.ts # 15 schema migrations
110110
│ │ ├── scheduler.ts # Background task scheduler
111111
│ │ ├── webhooks.ts # Outbound webhook delivery
112112
│ │ └── websocket.ts # Gateway WebSocket client

src/lib/db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function getDatabase(): Database.Database {
2323
db.pragma('journal_mode = WAL');
2424
db.pragma('synchronous = NORMAL');
2525
db.pragma('cache_size = 1000');
26+
db.pragma('foreign_keys = ON');
2627

2728
// Initialize schema if needed
2829
initializeSchema();

src/lib/migrations.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@ const migrations: Migration[] = [
424424
db.exec(`CREATE INDEX IF NOT EXISTS idx_users_provider ON users(provider)`)
425425
db.exec(`CREATE INDEX IF NOT EXISTS idx_users_email ON users(email)`)
426426
}
427+
},
428+
{
429+
id: '015_missing_indexes',
430+
up: (db) => {
431+
db.exec(`
432+
CREATE INDEX IF NOT EXISTS idx_notifications_read_at ON notifications(read_at);
433+
CREATE INDEX IF NOT EXISTS idx_notifications_recipient_read ON notifications(recipient, read_at);
434+
CREATE INDEX IF NOT EXISTS idx_activities_actor ON activities(actor);
435+
CREATE INDEX IF NOT EXISTS idx_activities_entity ON activities(entity_type, entity_id);
436+
CREATE INDEX IF NOT EXISTS idx_messages_read_at ON messages(read_at);
437+
`)
438+
}
427439
}
428440
]
429441

0 commit comments

Comments
 (0)