This commit is contained in:
Tomas Dvorak
2026-03-13 14:34:19 +01:00
parent 84a8acf944
commit 30d70a6aeb
126 changed files with 27297 additions and 29069 deletions
@@ -0,0 +1,41 @@
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")
}