summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-11-25 15:42:37 +0000
committerLibravatar GitHub <noreply@github.com>2024-11-25 15:42:37 +0000
commit3fceb5fc1a83a6ba3ca3c314eef50f0b45cd6009 (patch)
treed9fd78a82ec2352aad47d50cd9176e150f600b07 /vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go
parent[bugfix] notification types missing from link header (#3571) (diff)
downloadgotosocial-3fceb5fc1a83a6ba3ca3c314eef50f0b45cd6009.tar.xz
bumps uptrace/bun dependencies to v1.2.6 (#3569)
Diffstat (limited to 'vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go')
-rw-r--r--vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go b/vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go
new file mode 100644
index 000000000..00500061b
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/migrate/sqlschema/migrator.go
@@ -0,0 +1,49 @@
+package sqlschema
+
+import (
+ "fmt"
+
+ "github.com/uptrace/bun"
+ "github.com/uptrace/bun/schema"
+)
+
+type MigratorDialect interface {
+ schema.Dialect
+ NewMigrator(db *bun.DB, schemaName string) Migrator
+}
+
+type Migrator interface {
+ AppendSQL(b []byte, operation interface{}) ([]byte, error)
+}
+
+// migrator is a dialect-agnostic wrapper for sqlschema.MigratorDialect.
+type migrator struct {
+ Migrator
+}
+
+func NewMigrator(db *bun.DB, schemaName string) (Migrator, error) {
+ md, ok := db.Dialect().(MigratorDialect)
+ if !ok {
+ return nil, fmt.Errorf("%q dialect does not implement sqlschema.Migrator", db.Dialect().Name())
+ }
+ return &migrator{
+ Migrator: md.NewMigrator(db, schemaName),
+ }, nil
+}
+
+// BaseMigrator can be embeded by dialect's Migrator implementations to re-use some of the existing bun queries.
+type BaseMigrator struct {
+ db *bun.DB
+}
+
+func NewBaseMigrator(db *bun.DB) *BaseMigrator {
+ return &BaseMigrator{db: db}
+}
+
+func (m *BaseMigrator) AppendCreateTable(b []byte, model interface{}) ([]byte, error) {
+ return m.db.NewCreateTable().Model(model).AppendQuery(m.db.Formatter(), b)
+}
+
+func (m *BaseMigrator) AppendDropTable(b []byte, schemaName, tableName string) ([]byte, error) {
+ return m.db.NewDropTable().TableExpr("?.?", bun.Ident(schemaName), bun.Ident(tableName)).AppendQuery(m.db.Formatter(), b)
+}