mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2024-11-21 20:19:47 -05:00
28 lines
816 B
Go
28 lines
816 B
Go
package migrations
|
|
|
|
import (
|
|
"aim-oscar/models"
|
|
"context"
|
|
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/dbfixture"
|
|
)
|
|
|
|
func init() {
|
|
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
|
db.RegisterModel((*models.User)(nil), (*models.Message)(nil), (*models.Buddy)(nil), (*models.EmailVerification)(nil))
|
|
|
|
fixture := dbfixture.New(db, dbfixture.WithRecreateTables())
|
|
return fixture.Load(context.Background(), sqlMigrations, "20210505110026_fixtures.yml")
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
models := []interface{}{(*models.User)(nil), (*models.Message)(nil), (*models.Buddy)(nil), (*models.EmailVerification)(nil)}
|
|
|
|
for _, model := range models {
|
|
if _, err := db.NewDropTable().Model(model).Exec(ctx, nil); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|