Build every database's schema from embedded SQL files (closes #56)
check / check (push) Failing after 2m26s

The main database, each webhook's event database and each archive file
get their schema from SQL files under internal/db/migrations/, one
directory per kind. Opening a file runs, in one transaction, each file
that schema_migrations does not list. GORM stays for queries.
AutoMigrate is gone, tests included.

An event database holds only its own tables now, so the sweep that
removed target rows copied into it is deleted. The association guard
stays: without it a delivery write fails on the missing targets table.
The event totals row is inserted by events/001_schema.sql rather than
on every open.

Model: opus-5-5
This commit is contained in:
2026-10-13 02:00:36 +00:00
parent 957de7f99f
commit f69de8460c
23 changed files with 714 additions and 711 deletions
+5 -11
View File
@@ -314,21 +314,15 @@ func assertReplayTask(
)
}
// assertNoLeakedTarget proves the per-webhook database holds no target
// rows. AutoMigrate creates the table there because Delivery declares
// the relation, so it is a ROW that signals a leak: an association
// write would have upserted the whole target, plaintext config and
// all, into the event database. See
// assertNoLeakedTarget proves the per-webhook database holds no
// target: an association write would have upserted the whole target,
// plaintext config and all, into the event database. See
// https://git.eeqj.de/sneak/webhooker/issues/206.
func assertNoLeakedTarget(t *testing.T, webhookDB *gorm.DB) {
t.Helper()
var leaked int64
require.NoError(t, webhookDB.Unscoped().
Model(&database.Target{}).Count(&leaked).Error)
assert.Zero(
t, leaked,
assert.False(
t, webhookDB.Migrator().HasTable(&database.Target{}),
"replay must not write the target into the event database",
)
}