31 lines
691 B
Go
31 lines
691 B
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dwysokinski.me/twhelp/sessions/internal/bundb/internal/model"
|
|
"github.com/uptrace/bun"
|
|
)
|
|
|
|
func init() {
|
|
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
|
if _, err := db.NewCreateTable().
|
|
Model(&model.User{}).
|
|
Varchar(defaultVarcharLength).
|
|
Exec(ctx); err != nil {
|
|
return fmt.Errorf("couldn't create the 'users' table: %w", err)
|
|
}
|
|
return nil
|
|
}, func(ctx context.Context, db *bun.DB) error {
|
|
if _, err := db.NewDropTable().
|
|
Model(&model.User{}).
|
|
IfExists().
|
|
Cascade().
|
|
Exec(ctx); err != nil {
|
|
return fmt.Errorf("couldn't drop the 'users' table: %w", err)
|
|
}
|
|
return nil
|
|
})
|
|
}
|