//go:build integration package db_test import ( "os" "path/filepath" "testing" "music-server/internal/testutil/pgtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TestSQLDumps migrates real database dumps (music_*_dump.sql in the repository root, not committed). func TestSQLDumps(t *testing.T) { for _, dump := range []string{"music_ref_dump.sql", "music_test_dump.sql", "music_prod_dump.sql"} { t.Run(dump, func(t *testing.T) { path := filepath.Join("..", "..", dump) if _, err := os.Stat(path); err != nil { t.Skipf("%s not found", dump) } pgtest.CreateRole(t, "sansan") dbname := pgtest.NewDatabase(t) pgtest.LoadSQLFile(t, dbname, path) database := openDatabase(t, dbname) soundtracksBefore := count(t, database, "SELECT COUNT(*) FROM game") songsBefore := count(t, database, "SELECT COUNT(*) FROM song") require.NoError(t, database.RunMigrations()) assert.Equal(t, soundtracksBefore, count(t, database, "SELECT COUNT(*) FROM soundtrack")) assert.Equal(t, songsBefore, count(t, database, "SELECT COUNT(*) FROM song")) assert.Equal(t, 0, count(t, database, "SELECT COUNT(*) FROM song WHERE uuid IS NULL")) }) } }