Artifact 2c2b7ed8b28907bf71680f2665b11f356b59261fb1fda5a49965889ec6c6700e:
- File
db/schema_test.go
— part of check-in
[099ddb1b7a]
at
2026-07-19 15:24:52
on branch trunk
— Provision ticket schema at repo creation (#46)
Newly created repositories were missing the ticket and ticketchng tables and the ticketchng_idx1 index that fossil new provisions. Stock Fossil's web UI queries the ticket table unconditionally (e.g. info.c's artifact-detail lookup: SELECT 1 FROM ticket WHERE tkt_uuid GLOB ...), so opening a libfossil-created repository with the stock fossil binary and visiting /info/<uuid> crashed with "no such table: ticket".
Add the ticket and ticketchng table definitions and the ticketchng_idx1 index to schemaRepo2, taken verbatim from zRepositorySchema2 in fossil's src/schema.c, in the same position canonical fossil places them (after attachment_idx2, before cherrypick).
Verified against a real fossil new repository: sqlite_master table/ index diff and per-table .schema diff for ticket/ticketchng now match exactly. (user: [email protected], size: 1883) [annotate] [blame] [check-ins using]
package db_test import ( "path/filepath" "testing" "github.com/danmestas/libfossil/db" _ "github.com/danmestas/libfossil/internal/testdriver" ) func TestSeedNobody(t *testing.T) { path := filepath.Join(t.TempDir(), "test.fossil") d, err := db.Open(path) if err != nil { t.Fatalf("Open: %v", err) } defer d.Close() if err := db.CreateRepoSchema(d); err != nil { t.Fatalf("CreateRepoSchema: %v", err) } if err := db.SeedNobody(d, "oi"); err != nil { t.Fatalf("SeedNobody: %v", err) } var login, cap string err = d.QueryRow("SELECT login, cap FROM user WHERE login='nobody'").Scan(&login, &cap) if err != nil { t.Fatalf("nobody user not found: %v", err) } if cap != "oi" { t.Errorf("cap = %q, want oi", cap) } } // TestCreateRepoSchemaTicketTables asserts that a newly created repository // provisions the ticket, ticketchng tables and the ticketchng_idx1 index, // matching what canonical `fossil new` produces. Stock Fossil's web UI // queries the ticket table unconditionally (e.g. the artifact-prefix lookup // behind /info/<uuid>), so a repo missing this schema crashes stock tooling. func TestCreateRepoSchemaTicketTables(t *testing.T) { path := filepath.Join(t.TempDir(), "test.fossil") d, err := db.Open(path) if err != nil { t.Fatalf("Open: %v", err) } defer d.Close() if err := db.CreateRepoSchema(d); err != nil { t.Fatalf("CreateRepoSchema: %v", err) } for _, tbl := range []string{"ticket", "ticketchng"} { var name string err := d.QueryRow( "SELECT name FROM sqlite_master WHERE type='table' AND name=?", tbl, ).Scan(&name) if err != nil { t.Errorf("table %q not found: %v", tbl, err) } } var idxName string err = d.QueryRow( "SELECT name FROM sqlite_master WHERE type='index' AND name='ticketchng_idx1'", ).Scan(&idxName) if err != nil { t.Errorf("index ticketchng_idx1 not found: %v", err) } }