mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix: prevent deletion of assistant repo in deleteRepo
This commit is contained in:
1 parent
8133b655b0
commit
a0c97c9f41
3 files changed
+12
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in new issue
Block a user