home to your local SPACEGIRL 💫 arimelody.space
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

embed schema migration scripts

+15 -6
+14 -6
controller/migrator.go
··· 1 1 package controller 2 2 3 3 import ( 4 - "fmt" 5 - "os" 6 - "time" 4 + "embed" 5 + "fmt" 6 + "os" 7 + "time" 7 8 8 - "github.com/jmoiron/sqlx" 9 + "github.com/jmoiron/sqlx" 9 10 ) 10 11 11 - const DB_VERSION int = 4 12 + const DB_VERSION int = 5 12 13 13 14 func CheckDBVersionAndMigrate(db *sqlx.DB) { 14 15 db.MustExec("CREATE SCHEMA IF NOT EXISTS arimelody") ··· 49 50 ApplyMigration(db, "003-fail-lock") 50 51 oldDBVersion = 4 51 52 53 + case 4: 54 + ApplyMigration(db, "004-test") 55 + oldDBVersion = 5 56 + 52 57 } 53 58 } 54 59 55 60 fmt.Printf("Database schema up to date.\n") 56 61 } 57 62 63 + //go:embed "schema-migration" 64 + var schemaFS embed.FS 65 + 58 66 func ApplyMigration(db *sqlx.DB, scriptFile string) { 59 67 fmt.Printf("Applying schema migration %s...\n", scriptFile) 60 68 61 - bytes, err := os.ReadFile("schema-migration/" + scriptFile + ".sql") 69 + bytes, err := schemaFS.ReadFile("schema-migration/" + scriptFile + ".sql") 62 70 if err != nil { 63 71 fmt.Fprintf(os.Stderr, "FATAL: Failed to open schema file \"%s\": %v\n", scriptFile, err) 64 72 os.Exit(1)
+1
controller/schema-migration/004-test.sql
··· 1 + INSERT INTO arimelody.auditlog (level, type, content) VALUES (0, "test", "this is a db schema migration test!");
schema-migration/000-init.sql controller/schema-migration/000-init.sql
schema-migration/001-pre-versioning.sql controller/schema-migration/001-pre-versioning.sql
schema-migration/002-audit-logs.sql controller/schema-migration/002-audit-logs.sql
schema-migration/003-fail-lock.sql controller/schema-migration/003-fail-lock.sql