feat(02-01): add migration infrastructure with golang-migrate and embedded SQL
- RunMigrations applies versioned SQL files via golang-migrate + embed.FS (iofs) - ErrNoChange handled correctly - not treated as failure - Migration 0001 creates full current schema with CREATE TABLE IF NOT EXISTS - All three tables (updates, tags, tag_assignments) with acknowledged_at and ON DELETE CASCADE - Uses database/sqlite sub-package (modernc.org/sqlite, no CGO) - go mod tidy applied after adding dependencies
This commit is contained in:
28
pkg/diunwebhook/migrations/sqlite/0001_initial_schema.up.sql
Normal file
28
pkg/diunwebhook/migrations/sqlite/0001_initial_schema.up.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE IF NOT EXISTS updates (
|
||||
image TEXT PRIMARY KEY,
|
||||
diun_version TEXT NOT NULL DEFAULT '',
|
||||
hostname TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT '',
|
||||
provider TEXT NOT NULL DEFAULT '',
|
||||
hub_link TEXT NOT NULL DEFAULT '',
|
||||
mime_type TEXT NOT NULL DEFAULT '',
|
||||
digest TEXT NOT NULL DEFAULT '',
|
||||
created TEXT NOT NULL DEFAULT '',
|
||||
platform TEXT NOT NULL DEFAULT '',
|
||||
ctn_name TEXT NOT NULL DEFAULT '',
|
||||
ctn_id TEXT NOT NULL DEFAULT '',
|
||||
ctn_state TEXT NOT NULL DEFAULT '',
|
||||
ctn_status TEXT NOT NULL DEFAULT '',
|
||||
received_at TEXT NOT NULL,
|
||||
acknowledged_at TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tag_assignments (
|
||||
image TEXT PRIMARY KEY,
|
||||
tag_id INTEGER NOT NULL REFERENCES tags(id) ON DELETE CASCADE
|
||||
);
|
||||
Reference in New Issue
Block a user