aboutsummaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-12 02:52:22 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-12 02:53:52 +0300
commitd05ea66f4bbcf0cc5c8908f3435c68de1b070fa1 (patch)
tree7c7a769206646f2b81a0eda0680f0be5033a4197 /migrations
Начальная версияv0.0.1
Diffstat (limited to 'migrations')
-rw-r--r--migrations/20241005143542_init.go30
-rw-r--r--migrations/20241010175211_session.go34
-rw-r--r--migrations/main.go7
3 files changed, 71 insertions, 0 deletions
diff --git a/migrations/20241005143542_init.go b/migrations/20241005143542_init.go
new file mode 100644
index 0000000..9487cca
--- /dev/null
+++ b/migrations/20241005143542_init.go
@@ -0,0 +1,30 @@
+package migrations
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/uptrace/bun"
+ "go.neonxp.ru/framework/pkg/model"
+)
+
+//nolint:gochecknoinits
+func init() {
+ Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
+ fmt.Print(" [up migration] ")
+
+ if _, err := db.NewCreateTable().Model((*model.User)(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.User)(nil)).Exec(ctx); err != nil {
+ return err
+ }
+
+ return nil
+ })
+}
diff --git a/migrations/20241010175211_session.go b/migrations/20241010175211_session.go
new file mode 100644
index 0000000..8cb91ea
--- /dev/null
+++ b/migrations/20241010175211_session.go
@@ -0,0 +1,34 @@
+package migrations
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/uptrace/bun"
+ "go.neonxp.ru/framework/pkg/middleware/session"
+)
+
+//nolint:gochecknoinits
+func init() {
+ Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
+ fmt.Print(" [up migration] ")
+
+ if _, err := db.NewCreateTable().
+ Model((*session.Model)(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((*session.Model)(nil)).
+ Exec(ctx); err != nil {
+ return err
+ }
+
+ return nil
+ })
+}
diff --git a/migrations/main.go b/migrations/main.go
new file mode 100644
index 0000000..f7346fb
--- /dev/null
+++ b/migrations/main.go
@@ -0,0 +1,7 @@
+package migrations
+
+import (
+ "github.com/uptrace/bun/migrate"
+)
+
+var Migrations = migrate.NewMigrations()