package migrations import ( "context" "git.haelnorr.com/h/oslstats/internal/db" "github.com/uptrace/bun" ) func init() { Migrations.MustRegister( // UP migration func(ctx context.Context, conn *bun.DB) error { _, err := conn.NewCreateTable(). Model((*db.FixtureSchedule)(nil)). IfNotExists(). ForeignKey(`("fixture_id") REFERENCES "fixtures" ("id") ON DELETE CASCADE`). ForeignKey(`("proposed_by_team_id") REFERENCES "teams" ("id")`). ForeignKey(`("accepted_by_team_id") REFERENCES "teams" ("id")`). Exec(ctx) if err != nil { return err } // Create index on fixture_id for faster lookups _, err = conn.NewCreateIndex(). Model((*db.FixtureSchedule)(nil)). Index("idx_fixture_schedules_fixture_id"). Column("fixture_id"). IfNotExists(). Exec(ctx) if err != nil { return err } // Create index on status for filtering _, err = conn.NewCreateIndex(). Model((*db.FixtureSchedule)(nil)). Index("idx_fixture_schedules_status"). Column("status"). IfNotExists(). Exec(ctx) if err != nil { return err } return nil }, // DOWN migration func(ctx context.Context, conn *bun.DB) error { _, err := conn.NewDropTable(). Model((*db.FixtureSchedule)(nil)). IfExists(). Exec(ctx) return err }, ) }