mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat: add explicit OpenCode host import and repo relink (#176)
* feat: add explicit OpenCode host import and repo relink * fix: tighten OpenCode import and relink reporting * Add OpenCode config schema and JSONC parser imports * Fix repo relinking and state availability detection for config-only imports * Remove unused exports and internalize row-shape types * Remove unused reserveScheduleJobNextRun function --------- Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
1 parent
173dbf578e
commit
6b1a1e2005
15 files changed
+1031
-245
No files matched your search
@@ -34,10 +34,6 @@ function markApplied(db: Database, migration: Migration): void {
|
||||
.run(migration.version, migration.name, Date.now())
|
||||
}
|
||||
|
||||
function markReverted(db: Database, version: number): void {
|
||||
db.prepare('DELETE FROM schema_migrations WHERE version = ?').run(version)
|
||||
}
|
||||
|
||||
export function migrate(db: Database, migrations: Migration[]): void {
|
||||
ensureMigrationsTable(db)
|
||||
|
||||
@@ -70,49 +66,4 @@ export function migrate(db: Database, migrations: Migration[]): void {
|
||||
logger.info('All migrations applied successfully')
|
||||
}
|
||||
|
||||
export function rollback(db: Database, migrations: Migration[], targetVersion?: number): void {
|
||||
ensureMigrationsTable(db)
|
||||
|
||||
const applied = getAppliedVersions(db)
|
||||
const sorted = [...migrations]
|
||||
.filter(m => applied.has(m.version))
|
||||
.sort((a, b) => b.version - a.version)
|
||||
|
||||
if (sorted.length === 0) {
|
||||
logger.info('No migrations to rollback')
|
||||
return
|
||||
}
|
||||
|
||||
const latest = sorted[0]
|
||||
if (!latest) {
|
||||
logger.info('No migrations to rollback')
|
||||
return
|
||||
}
|
||||
const target = targetVersion ?? latest.version - 1
|
||||
|
||||
const toRevert = sorted.filter(m => m.version > target)
|
||||
|
||||
if (toRevert.length === 0) {
|
||||
logger.info('No migrations to rollback')
|
||||
return
|
||||
}
|
||||
|
||||
logger.info(`Rolling back ${toRevert.length} migration(s) to version ${target}`)
|
||||
|
||||
for (const migration of toRevert) {
|
||||
logger.info(`Reverting migration ${migration.version}: ${migration.name}`)
|
||||
db.run('BEGIN TRANSACTION')
|
||||
try {
|
||||
migration.down(db)
|
||||
markReverted(db, migration.version)
|
||||
db.run('COMMIT')
|
||||
logger.info(`Migration ${migration.version} reverted successfully`)
|
||||
} catch (error) {
|
||||
db.run('ROLLBACK')
|
||||
logger.error(`Rollback of migration ${migration.version} failed:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('Rollback completed successfully')
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { getReposPath } from '@opencode-manager/shared/config/env'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
import path from 'path'
|
||||
|
||||
export interface RepoRow {
|
||||
interface RepoRow {
|
||||
id: number
|
||||
repo_url?: string
|
||||
local_path: string
|
||||
|
||||
@@ -204,11 +204,6 @@ export function deleteScheduleJob(db: Database, repoId: number, jobId: number):
|
||||
return result.changes > 0
|
||||
}
|
||||
|
||||
export function reserveScheduleJobNextRun(db: Database, repoId: number, jobId: number, nextRunAt: number): void {
|
||||
const stmt = db.prepare('UPDATE schedule_jobs SET next_run_at = ?, updated_at = ? WHERE repo_id = ? AND id = ?')
|
||||
stmt.run(nextRunAt, Date.now(), repoId, jobId)
|
||||
}
|
||||
|
||||
export function updateScheduleJobRunState(db: Database, repoId: number, jobId: number, values: { lastRunAt: number; nextRunAt?: number | null }): void {
|
||||
const stmt = db.prepare('UPDATE schedule_jobs SET last_run_at = ?, next_run_at = ?, updated_at = ? WHERE repo_id = ? AND id = ?')
|
||||
stmt.run(values.lastRunAt, values.nextRunAt ?? null, Date.now(), repoId, jobId)
|
||||
|
||||
Reference in new issue
Block a user