Преглед на файлове

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)
+}