Files
MyClub/database/goosemigrations/20260313000100_bootstrap_legacy_schema.go
T
Tomas Dvorak 30d70a6aeb update
2026-03-13 14:34:19 +01:00

42 lines
977 B
Go

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")
}