Move schema_migrations table creation into 000.sql with INTEGER version column #56

Closed
opened 2026-03-25 02:22:02 +01:00 by clawbot · 3 comments
Collaborator

Per sneak/pixa PR #36, the standard migrations pattern should be:

  1. schema_migrations table DDL lives in 000.sql (not inline Go code)
  2. version column is INTEGER PRIMARY KEY (not TEXT)
  3. 000.sql is self-contained — contains both CREATE TABLE IF NOT EXISTS and INSERT OR IGNORE INTO schema_migrations (version) VALUES (0)
  4. Go code does zero INSERTs for the bootstrap — just reads and executes 000.sql

This repo currently creates the migrations table inline in Go code. It should be moved to follow the pixa pattern.

Reference implementation: sneak/pixa 000.sql and database.go.

Per [sneak/pixa PR #36](https://git.eeqj.de/sneak/pixa/pulls/36), the standard migrations pattern should be: 1. **`schema_migrations` table DDL lives in `000.sql`** (not inline Go code) 2. **`version` column is `INTEGER PRIMARY KEY`** (not TEXT) 3. **`000.sql` is self-contained** — contains both `CREATE TABLE IF NOT EXISTS` and `INSERT OR IGNORE INTO schema_migrations (version) VALUES (0)` 4. **Go code does zero INSERTs** for the bootstrap — just reads and executes `000.sql` This repo currently creates the migrations table inline in Go code. It should be moved to follow the pixa pattern. Reference implementation: [sneak/pixa `000.sql`](https://git.eeqj.de/sneak/pixa/src/branch/main/internal/database/schema/000.sql) and [`database.go`](https://git.eeqj.de/sneak/pixa/src/branch/main/internal/database/database.go).
Author
Collaborator

Blocking premise mismatch found while starting this: webhooker does not currently create a schema_migrations table in Go code. There is no schema_migrations table anywhere (not in the code, not in git history) and no .sql migration files. Schema is managed entirely via GORM AutoMigrate — internal/database/models.go Migrate() for the main DB, and per-webhook event DBs in internal/database/webhook_db_manager.go. So there is nothing to "move" into 000.sql.

Adopting the pixa numbered-SQL pattern here would be a from-scratch architecture change (replace AutoMigrate with hand-written SQL DDL for ~9 models across two DB tiers, plus an apply loop and embed) — much larger than #56 as written, and not behavior-preserving. The alternative, a vestigial schema_migrations table alongside AutoMigrate, tracks nothing real.

Your call: (a) close #56 as not-applicable and keep AutoMigrate, or (b) commit to the full SQL-migration conversion as a larger tracked task. Recommend (a) unless you specifically want SQL-file migrations. Assigning to you.

Blocking premise mismatch found while starting this: webhooker does not currently create a `schema_migrations` table in Go code. There is no `schema_migrations` table anywhere (not in the code, not in git history) and no `.sql` migration files. Schema is managed entirely via GORM `AutoMigrate` — `internal/database/models.go` `Migrate()` for the main DB, and per-webhook event DBs in `internal/database/webhook_db_manager.go`. So there is nothing to "move" into `000.sql`. Adopting the pixa numbered-SQL pattern here would be a from-scratch architecture change (replace `AutoMigrate` with hand-written SQL DDL for ~9 models across two DB tiers, plus an apply loop and embed) — much larger than #56 as written, and not behavior-preserving. The alternative, a vestigial `schema_migrations` table alongside `AutoMigrate`, tracks nothing real. Your call: (a) close #56 as not-applicable and keep `AutoMigrate`, or (b) commit to the full SQL-migration conversion as a larger tracked task. Recommend (a) unless you specifically want SQL-file migrations. Assigning to you.
sneak was assigned by clawbot 2026-07-26 20:44:35 +02:00
Author
Collaborator

REPO_POLICIES.md already decides this, so it comes off your list. The schema lives in SQL files embedded in the binary under internal/db/migrations/: 000_migration.sql creates only the tracking table, and 001_schema.sql holds the full schema, edited directly before 1.0. The earlier recommendation to close this missed that rule.

webhooker builds its schema with GORM AutoMigrate in three places: the main database, the per-webhook event databases and the archive files. The fleet builds the conversion: one 000_migration.sql and one 001_schema.sql per kind of database file, applied when the file is opened, in place of AutoMigrate. GORM stays for queries. This also drops the parent tables that AutoMigrate adds to every event database, and the sweep that removes them. Reassigned to clawbot.

Model: opus-5-5

`REPO_POLICIES.md` already decides this, so it comes off your list. The schema lives in SQL files embedded in the binary under `internal/db/migrations/`: `000_migration.sql` creates only the tracking table, and `001_schema.sql` holds the full schema, edited directly before 1.0. The earlier recommendation to close this missed that rule. webhooker builds its schema with GORM `AutoMigrate` in three places: the main database, the per-webhook event databases and the archive files. The fleet builds the conversion: one `000_migration.sql` and one `001_schema.sql` per kind of database file, applied when the file is opened, in place of `AutoMigrate`. GORM stays for queries. This also drops the parent tables that `AutoMigrate` adds to every event database, and the sweep that removes them. Reassigned to clawbot. Model: opus-5-5
sneak was unassigned by clawbot 2026-10-13 03:15:16 +02:00
clawbot self-assigned this 2026-10-13 03:15:16 +02:00
Author
Collaborator

Built in #519. Each kind of database file has 000_migration.sql and 001_schema.sql under internal/db/migrations/ (main/, events/, archive/), applied in one transaction when the file is opened, in place of AutoMigrate. Event databases no longer carry copies of the main database's tables, and the sweep that cleaned them is gone.

Model: opus-5-5

Built in https://git.eeqj.de/sneak/webhooker/pulls/519. Each kind of database file has `000_migration.sql` and `001_schema.sql` under `internal/db/migrations/` (`main/`, `events/`, `archive/`), applied in one transaction when the file is opened, in place of `AutoMigrate`. Event databases no longer carry copies of the main database's tables, and the sweep that cleaned them is gone. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/webhooker#56