Skip to content

Commit a0c97c9

Browse files
fix: prevent deletion of assistant repo in deleteRepo
1 parent 8133b65 commit a0c97c9

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

backend/src/db/queries.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ export function updateRepoBranch(db: Database, id: number, branch: string): void
281281
}
282282

283283
export function deleteRepo(db: Database, id: number): void {
284+
if (id === ASSISTANT_REPO_ID) {
285+
return
286+
}
287+
284288
for (const table of TABLES_WITH_REPO_ID) {
285289
db.prepare(`DELETE FROM ${table} WHERE repo_id = ?`).run(id)
286290
}

backend/src/db/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { dirname } from 'path'
55
import { migrate } from './migration-runner'
66
import { allMigrations } from './migrations'
77
import { ensureOpenCodeModelStateTable } from './model-state'
8+
import { ensureAssistantRepo } from './queries'
89

910
export function initializeDatabase(dbPath: string = './data/opencode.db'): Database {
1011
mkdirSync(dirname(dbPath), { recursive: true })
@@ -15,6 +16,7 @@ export function initializeDatabase(dbPath: string = './data/opencode.db'): Datab
1516

1617
db.prepare('INSERT OR IGNORE INTO user_preferences (user_id, preferences, updated_at) VALUES (?, ?, ?)')
1718
.run('default', '{}', Date.now())
19+
ensureAssistantRepo(db)
1820

1921
logger.info('Database initialized successfully')
2022

backend/test/db/queries.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ describe('Database Queries', () => {
282282
)
283283
expect(deleteRepoStmt.run).toHaveBeenCalledWith(1)
284284
})
285+
286+
it('should not delete the assistant repo', () => {
287+
db.deleteRepo(mockDb, 0)
288+
289+
expect(mockDb.prepare).not.toHaveBeenCalled()
290+
})
285291
})
286292

287293
describe('Database Schema', () => {

0 commit comments

Comments
 (0)