mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 19:03:43 +00:00
feat: add PostgreSQL migration runner
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
"github.com/cosmic-clash/cosmic-clash/server/migrations"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
)
|
||||
|
||||
@@ -40,18 +41,11 @@ func openIntegrationPostgres(t *testing.T) *sql.DB {
|
||||
|
||||
func applyIntegrationMigrations(t *testing.T, db *sql.DB) {
|
||||
t.Helper()
|
||||
if _, err := db.ExecContext(context.Background(), `DROP TABLE IF EXISTS assignments, audit_events, outbox, result_receipts, ranked_season_rollovers, penalties, seasons, ratings, match_participants, matches, proposal_participants, proposals, queue_tickets, idempotency_keys, sessions, identities CASCADE`); err != nil {
|
||||
if _, err := db.ExecContext(context.Background(), `DROP TABLE IF EXISTS schema_migrations, assignments, audit_events, outbox, result_receipts, ranked_season_rollovers, penalties, seasons, ratings, match_participants, matches, proposal_participants, proposals, queue_tickets, idempotency_keys, sessions, identities CASCADE`); err != nil {
|
||||
t.Fatalf("reset PostgreSQL schema: %v", err)
|
||||
}
|
||||
for _, name := range []string{"0001_initial.sql", "0002_assignments.sql"} {
|
||||
path := filepath.Join("..", "migrations", name)
|
||||
sqlBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.ExecContext(context.Background(), string(sqlBytes)); err != nil {
|
||||
t.Fatalf("apply %s: %v", name, err)
|
||||
}
|
||||
if err := migrations.Apply(context.Background(), db, filepath.Join("..", "migrations")); err != nil {
|
||||
t.Fatalf("apply migrations: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user