aboutsummaryrefslogtreecommitdiff
path: root/cmd/bun/migrations/20241005143542_1_init.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/bun/migrations/20241005143542_1_init.go')
-rw-r--r--cmd/bun/migrations/20241005143542_1_init.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/cmd/bun/migrations/20241005143542_1_init.go b/cmd/bun/migrations/20241005143542_1_init.go
new file mode 100644
index 0000000..dc92797
--- /dev/null
+++ b/cmd/bun/migrations/20241005143542_1_init.go
@@ -0,0 +1,27 @@
+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.NewCreateTable().Model((*model.Quote)(nil)).Exec(ctx); err != nil {
+ return err
+ }
+
+ return nil
+ }, func(ctx context.Context, db *bun.DB) error {
+ fmt.Print(" [down migration] ")
+ if _, err := db.NewDropTable().Model((*model.Quote)(nil)).Exec(ctx); err != nil {
+ return err
+ }
+
+ return nil
+ })
+}