package goosemigrations import ( "context" "database/sql" "errors" "fotbal-club/internal/dbschema" "github.com/pressly/goose/v3" "gorm.io/driver/postgres" "gorm.io/gorm" gormlogger "gorm.io/gorm/logger" ) func init() { goose.AddMigrationContext(upBootstrapLegacySchema, downBootstrapLegacySchema) } func upBootstrapLegacySchema(ctx context.Context, tx *sql.Tx) error { if _, err := tx.ExecContext(ctx, ` CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS "pgcrypto"; `); err != nil { return err } gormDB, err := gorm.Open(postgres.New(postgres.Config{Conn: tx}), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true, Logger: gormlogger.Default.LogMode(gormlogger.Silent), }) if err != nil { return err } return dbschema.AutoMigrate(gormDB) } func downBootstrapLegacySchema(context.Context, *sql.Tx) error { return errors.New("bootstrap schema migration is irreversible") }