From 420e049415c8ec7f7a209a03110eecbe0c83e9e0 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 7 Oct 2024 01:06:55 +0300 Subject: Мелкие правки MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/20241005143542_1_init.go | 27 +++++++++++++++++++++++++++ migrations/main.go | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 migrations/20241005143542_1_init.go create mode 100644 migrations/main.go (limited to 'migrations') diff --git a/migrations/20241005143542_1_init.go b/migrations/20241005143542_1_init.go new file mode 100644 index 0000000..dc92797 --- /dev/null +++ b/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 + }) +} 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() -- cgit v1.2.3