Artifact 45fdb1241a4be171e68e00331c7cbd4b3a7159168ea603c544a3320e4239c1d2:
- File
cli/repo_schema.go
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 4885) [annotate] [blame] [check-ins using]
package cli import ( "encoding/json" "fmt" "os" "strings" "time" "github.com/danmestas/go-libfossil/internal/repo" ) // RepoSchemaCmd groups synced table schema operations. type RepoSchemaCmd struct { Add RepoSchemaAddCmd `cmd:"" help:"Register a new synced table"` List RepoSchemaListCmd `cmd:"" help:"List registered synced tables"` Show RepoSchemaShowCmd `cmd:"" help:"Show table schema details"` Remove RepoSchemaRemoveCmd `cmd:"" help:"Remove a synced table registration"` } // RepoSchemaAddCmd registers a new synced table. type RepoSchemaAddCmd struct { Name string `arg:"" help:"Table name (without x_ prefix)"` Columns string `required:"" help:"Column defs: name:type[:pk],... (e.g. peer_id:text:pk,addr:text)"` Conflict string `default:"mtime-wins" enum:"self-write,mtime-wins,owner-write" help:"Conflict strategy"` } func (c *RepoSchemaAddCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() inner := r.Inner() if err := repo.EnsureSyncSchema(inner.DB()); err != nil { return err } colDefs, err := parseColumnDefs(c.Columns) if err != nil { return err } def := repo.TableDef{ Columns: colDefs, Conflict: c.Conflict, } mtime := time.Now().Unix() if err := repo.RegisterSyncedTable(inner.DB(), c.Name, def, mtime); err != nil { return err } fmt.Printf("Registered table %q with %d columns (%s)\n", c.Name, len(colDefs), c.Conflict) return nil } // RepoSchemaListCmd lists registered synced tables. type RepoSchemaListCmd struct{} func (c *RepoSchemaListCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() inner := r.Inner() if err := repo.EnsureSyncSchema(inner.DB()); err != nil { return err } tables, err := repo.ListSyncedTables(inner.DB()) if err != nil { return err } if len(tables) == 0 { fmt.Println("(no synced tables registered)") return nil } fmt.Printf("%-20s %-15s %s\n", "TABLE", "CONFLICT", "COLUMNS") fmt.Printf("%-20s %-15s %s\n", strings.Repeat("-", 20), strings.Repeat("-", 15), strings.Repeat("-", 7)) for _, t := range tables { fmt.Printf("%-20s %-15s %d\n", t.Name, t.Def.Conflict, len(t.Def.Columns)) } return nil } // RepoSchemaShowCmd shows table schema details. type RepoSchemaShowCmd struct { Name string `arg:"" help:"Table name (without x_ prefix)"` } func (c *RepoSchemaShowCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() inner := r.Inner() if err := repo.EnsureSyncSchema(inner.DB()); err != nil { return err } tables, err := repo.ListSyncedTables(inner.DB()) if err != nil { return err } var found *repo.TableInfo for _, t := range tables { if t.Name == c.Name { t := t found = &t break } } if found == nil { return fmt.Errorf("table %q not found", c.Name) } enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") return enc.Encode(found) } // RepoSchemaRemoveCmd removes a synced table registration. type RepoSchemaRemoveCmd struct { Name string `arg:"" help:"Table name (without x_ prefix)"` } func (c *RepoSchemaRemoveCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() inner := r.Inner() if err := repo.EnsureSyncSchema(inner.DB()); err != nil { return err } if err := repo.ValidateTableName(c.Name); err != nil { return err } tables, err := repo.ListSyncedTables(inner.DB()) if err != nil { return err } found := false for _, t := range tables { if t.Name == c.Name { found = true break } } if !found { return fmt.Errorf("table %q not registered", c.Name) } if _, err := inner.DB().Exec("DELETE FROM _sync_schema WHERE name=?", c.Name); err != nil { return fmt.Errorf("delete from _sync_schema: %w", err) } dropSQL := fmt.Sprintf("DROP TABLE IF EXISTS x_%s", c.Name) if _, err := inner.DB().Exec(dropSQL); err != nil { return fmt.Errorf("drop table: %w", err) } fmt.Printf("Removed table %q and dropped x_%s\n", c.Name, c.Name) return nil } func parseColumnDefs(s string) ([]repo.ColumnDef, error) { if s == "" { return nil, fmt.Errorf("column definitions must not be empty") } parts := strings.Split(s, ",") var cols []repo.ColumnDef for _, part := range parts { part = strings.TrimSpace(part) if part == "" { continue } fields := strings.Split(part, ":") if len(fields) < 2 { return nil, fmt.Errorf("column definition %q must have at least name:type", part) } col := repo.ColumnDef{ Name: strings.TrimSpace(fields[0]), Type: strings.TrimSpace(fields[1]), PK: false, } if len(fields) >= 3 && strings.TrimSpace(fields[2]) == "pk" { col.PK = true } cols = append(cols, col) } if len(cols) == 0 { return nil, fmt.Errorf("no valid columns found in definition") } return cols, nil }