mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
update
This commit is contained in:
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user