MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / runMigrations

Method runMigrations

internal/metadata/store.go:420–446  ·  view source on GitHub ↗

runMigrations applies idempotent data migrations after the schema exists.

(ctx context.Context, db *sql.DB)

Source from the content-addressed store, hash-verified

418
419// runMigrations applies idempotent data migrations after the schema exists.
420func (s *Store) runMigrations(ctx context.Context, db *sql.DB) error {
421 if _, err := db.ExecContext(ctx, migrationMetaSQL); err != nil {
422 return fmt.Errorf("migration meta: %w", err)
423 }
424 migrations := []struct {
425 id string
426 run func(context.Context, *sql.DB) error
427 }{
428 {id: "prompt_to_instruction", run: s.migratePromptToInstruction},
429 }
430 for _, migration := range migrations {
431 var applied int
432 if err := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM migration_meta WHERE id = ?`, migration.id).Scan(&applied); err != nil {
433 return fmt.Errorf("migration check %s: %w", migration.id, err)
434 }
435 if applied > 0 {
436 continue
437 }
438 if err := migration.run(ctx, db); err != nil {
439 return fmt.Errorf("migration %s: %w", migration.id, err)
440 }
441 if _, err := db.ExecContext(ctx, `INSERT INTO migration_meta(id, applied_at) VALUES(?, ?)`, migration.id, timeNow()); err != nil {
442 return fmt.Errorf("migration record %s: %w", migration.id, err)
443 }
444 }
445 return nil
446}
447
448func (s *Store) migratePromptToInstruction(ctx context.Context, db *sql.DB) error {
449 for _, table := range []string{"metadata_items", "metadata_sources"} {

Callers 1

InitMethod · 0.95

Calls 2

timeNowFunction · 0.85
QueryRowContextMethod · 0.80

Tested by

no test coverage detected