34 lines
627 B
Go
34 lines
627 B
Go
|
package migrations
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/uptrace/bun"
|
||
|
"sh.org.ru/pkg/model"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
|
||
|
fmt.Print(" [up migration] ")
|
||
|
if _, err := db.NewAddColumn().
|
||
|
Model((*model.Quote)(nil)).
|
||
|
ColumnExpr("rating INT NOT NULL DEFAULT '0'").
|
||
|
Exec(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}, func(ctx context.Context, db *bun.DB) error {
|
||
|
fmt.Print(" [down migration] ")
|
||
|
if _, err := db.NewDropColumn().
|
||
|
Model((*model.Quote)(nil)).
|
||
|
Column("rating").
|
||
|
Exec(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
})
|
||
|
}
|