32 lines
643 B
Go
32 lines
643 B
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/uptrace/bun"
|
|
|
|
"git.k6n.net/mats/fullstack-template/internal/items"
|
|
)
|
|
|
|
func init() {
|
|
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
|
_, err := db.NewCreateTable().
|
|
Model((*items.Item)(nil)).
|
|
IfNotExists().
|
|
Exec(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = db.NewCreateIndex().
|
|
Model((*items.Item)(nil)).
|
|
IfNotExists().
|
|
Index("items_status_idx").
|
|
Column("status").
|
|
Exec(ctx)
|
|
return err
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
_, err := db.NewDropTable().Model((*items.Item)(nil)).IfExists().Exec(ctx)
|
|
return err
|
|
})
|
|
}
|