beads/internal/storage/dolt/migrations.go
beads/crew/emma 2137693dad revert: restore embedded Dolt mode (was only supposed to be removed from Gas Town)
Revert commits e5330641 and 0df41523 which removed embedded Dolt mode
from the beads codebase. The embedded Dolt removal was only intended for
Gas Town, not for Beads.

Restores:
- dolthub/driver dependency and embedded connection path
- Advisory flock (AccessLock) for concurrent process protection
- Embedded connector lifecycle management in DoltStore
- All CGO build tags across ~45 files
- Vendored go-icu-regex library
- nocgo stub files for non-CGO builds
- Bootstrap and embedded_uow helpers
- factory_dolt_test.go and dolt_singleprocess_test.go

Merge conflict resolutions:
- store.go: TCP fail-fast check wrapped inside if cfg.ServerMode
- store.go: backtick-quoting for embedded CREATE DATABASE (prefix-based names)
- perf_dolt.go: port references updated from 3306 to 3307
- ci.yml: restored continue-on-error for Nix (dolthub/driver requires Go 1.25.6+)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-07 21:21:24 -08:00

56 lines
1.6 KiB
Go

//go:build cgo
package dolt
import (
"database/sql"
"fmt"
"log"
"strings"
"github.com/steveyegge/beads/internal/storage/dolt/migrations"
)
// Migration represents a single schema migration for Dolt.
type Migration struct {
Name string
Func func(*sql.DB) error
}
// migrationsList is the ordered list of all Dolt schema migrations.
// Each migration must be idempotent - safe to run multiple times.
// New migrations should be appended to the end of this list.
var migrationsList = []Migration{
{"wisp_type_column", migrations.MigrateWispTypeColumn},
{"spec_id_column", migrations.MigrateSpecIDColumn},
}
// RunMigrations executes all registered Dolt migrations in order.
// Each migration is idempotent and checks whether its changes have
// already been applied before making modifications.
func RunMigrations(db *sql.DB) error {
for _, m := range migrationsList {
if err := m.Func(db); err != nil {
return fmt.Errorf("dolt migration %q failed: %w", m.Name, err)
}
}
// Commit schema changes via Dolt (idempotent - no-ops if nothing changed)
_, err := db.Exec("CALL DOLT_COMMIT('-Am', 'schema: auto-migrate')")
if err != nil {
// "nothing to commit" is expected when migrations were already applied
if !strings.Contains(strings.ToLower(err.Error()), "nothing to commit") {
log.Printf("dolt migration commit warning: %v", err)
}
}
return nil
}
// ListMigrations returns the names of all registered migrations.
func ListMigrations() []string {
names := make([]string, len(migrationsList))
for i, m := range migrationsList {
names[i] = m.Name
}
return names
}