big ole refactor
This commit is contained in:
67
internal/db/migrations/20260210182212_add_leagues.go
Normal file
67
internal/db/migrations/20260210182212_add_leagues.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/db"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Migrations.MustRegister(
|
||||
// UP migration
|
||||
func(ctx context.Context, conn *bun.DB) error {
|
||||
// Add slap_version column to seasons table
|
||||
_, err := conn.NewAddColumn().
|
||||
Model((*db.Season)(nil)).
|
||||
ColumnExpr("slap_version VARCHAR NOT NULL DEFAULT 'rebound'").
|
||||
IfNotExists().
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create leagues table
|
||||
_, err = conn.NewCreateTable().
|
||||
Model((*db.League)(nil)).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create season_leagues join table
|
||||
_, err = conn.NewCreateTable().
|
||||
Model((*db.SeasonLeague)(nil)).
|
||||
Exec(ctx)
|
||||
return err
|
||||
},
|
||||
// DOWN migration
|
||||
func(ctx context.Context, conn *bun.DB) error {
|
||||
// Drop season_leagues join table first
|
||||
_, err := conn.NewDropTable().
|
||||
Model((*db.SeasonLeague)(nil)).
|
||||
IfExists().
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Drop leagues table
|
||||
_, err = conn.NewDropTable().
|
||||
Model((*db.League)(nil)).
|
||||
IfExists().
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Remove slap_version column from seasons table
|
||||
_, err = conn.NewDropColumn().
|
||||
Model((*db.Season)(nil)).
|
||||
ColumnExpr("slap_version").
|
||||
Exec(ctx)
|
||||
return err
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user