···88 "github.com/jmoiron/sqlx"
99)
10101111-const DB_VERSION int = 2
1111+const DB_VERSION int = 3
12121313func CheckDBVersionAndMigrate(db *sqlx.DB) {
1414 db.MustExec("CREATE SCHEMA IF NOT EXISTS arimelody")
···4040 // into the old database in order for this to work LOL
4141 ApplyMigration(db, "001-pre-versioning")
4242 oldDBVersion = 2
4343+4444+ case 2:
4545+ ApplyMigration(db, "002-audit-logs")
4646+ oldDBVersion = 3
43474448 }
4549 }
···22-- Tables
33--
4455+-- Audit logs
66+CREATE TABLE arimelody.auditlog (
77+ id UUID DEFAULT gen_random_uuid(),
88+ level int NOT NULL DEFAULT 0,
99+ type TEXT NOT NULL,
1010+ content TEXT NOT NULL,
1111+ created_at TIMESTAMP NOT NULL DEFAULT current_timestamp
1212+);
1313+514-- Accounts
615CREATE TABLE arimelody.account (
716 id UUID DEFAULT gen_random_uuid(),
···918 password TEXT NOT NULL,
1019 email TEXT,
1120 avatar_url TEXT,
1212- created_at TIMESTAMP DEFAULT current_timestamp
2121+ created_at TIMESTAMP NOT NULL DEFAULT current_timestamp
1322);
1423ALTER TABLE arimelody.account ADD CONSTRAINT account_pk PRIMARY KEY (id);
1524···7483 buyname text,
7584 buylink text,
7685 copyright text,
7777- copyrightURL text
8686+ copyrightURL text,
8787+ created_at TIMESTAMP NOT NULL DEFAULT current_timestamp,
7888);
7989ALTER TABLE arimelody.musicrelease ADD CONSTRAINT musicrelease_pk PRIMARY KEY (id);
8090
+12
schema-migration/002-audit-logs.sql
···11+-- Audit logs
22+CREATE TABLE arimelody.auditlog (
33+ id UUID DEFAULT gen_random_uuid(),
44+ level int NOT NULL DEFAULT 0,
55+ type TEXT NOT NULL,
66+ content TEXT NOT NULL,
77+ created_at TIMESTAMP NOT NULL DEFAULT current_timestamp
88+);
99+1010+-- Need moar timestamps
1111+ALTER TABLE arimelody.musicrelease ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT current_timestamp;
1212+ALTER TABLE arimelody.account ALTER COLUMN created_at SET NOT NULL;