diff options
Diffstat (limited to 'migrations/20241007210540_2_rating.go')
-rw-r--r-- | migrations/20241007210540_2_rating.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/migrations/20241007210540_2_rating.go b/migrations/20241007210540_2_rating.go new file mode 100644 index 0000000..06acb72 --- /dev/null +++ b/migrations/20241007210540_2_rating.go @@ -0,0 +1,33 @@ +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 + }) +} |