浏览代码

feat: add db testing method

Yeuoly 11 月之前
父节点
当前提交
d768c548d4
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      internal/db/pgsql.go

+ 20 - 0
internal/db/pgsql.go

@@ -304,3 +304,23 @@ func WithTransaction(fn func(tx *gorm.DB) error, ctx ...*gorm.DB) error {
 	tx.Commit()
 	return nil
 }
+
+// NOTE: not used in production, only for testing
+func DropTable(model any) error {
+	return DifyPluginDB.Migrator().DropTable(model)
+}
+
+// NOTE: not used in production, only for testing
+func DropDatabase(dbname string) error {
+	return DifyPluginDB.Exec(fmt.Sprintf("DROP DATABASE %s", dbname)).Error
+}
+
+// NOTE: not used in production, only for testing
+func CreateDatabase(dbname string) error {
+	return DifyPluginDB.Exec(fmt.Sprintf("CREATE DATABASE %s", dbname)).Error
+}
+
+// NOTE: not used in production, only for testing
+func CreateTable(model any) error {
+	return DifyPluginDB.Migrator().CreateTable(model)
+}