fix: prevent deletion of assistant repo in deleteRepo

This commit is contained in:
Chris Scott committed 2026-06-09 14:56:54 -04:00
1 parent 8133b655b0
commit a0c97c9f41
3 files changed
+12

No files matched your search

+4
View File
@@ -281,6 +281,10 @@ export function updateRepoBranch(db: Database, id: number, branch: string): void
}
export function deleteRepo(db: Database, id: number): void {
if (id === ASSISTANT_REPO_ID) {
return
}
for (const table of TABLES_WITH_REPO_ID) {
db.prepare(`DELETE FROM ${table} WHERE repo_id = ?`).run(id)
}
+2
View File
@@ -5,6 +5,7 @@ import { dirname } from 'path'
import { migrate } from './migration-runner'
import { allMigrations } from './migrations'
import { ensureOpenCodeModelStateTable } from './model-state'
import { ensureAssistantRepo } from './queries'
export function initializeDatabase(dbPath: string = './data/opencode.db'): Database {
mkdirSync(dirname(dbPath), { recursive: true })
@@ -15,6 +16,7 @@ export function initializeDatabase(dbPath: string = './data/opencode.db'): Datab
db.prepare('INSERT OR IGNORE INTO user_preferences (user_id, preferences, updated_at) VALUES (?, ?, ?)')
.run('default', '{}', Date.now())
ensureAssistantRepo(db)
logger.info('Database initialized successfully')
+6
View File
@@ -282,6 +282,12 @@ describe('Database Queries', () => {
)
expect(deleteRepoStmt.run).toHaveBeenCalledWith(1)
})
it('should not delete the assistant repo', () => {
db.deleteRepo(mockDb, 0)
expect(mockDb.prepare).not.toHaveBeenCalled()
})
})
describe('Database Schema', () => {