rake-db 2.3.25 → 2.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1050,6 +1050,12 @@ class MigrationBase {
1050
1050
  dropExtension(name, options = {}) {
1051
1051
  return createExtension$1(this, !this.up, name, options);
1052
1052
  }
1053
+ createEnum(name, values, options) {
1054
+ return createEnum(this, this.up, name, values, options);
1055
+ }
1056
+ dropEnum(name, values, options) {
1057
+ return createEnum(this, !this.up, name, values, options);
1058
+ }
1053
1059
  async tableExists(tableName) {
1054
1060
  return queryExists(this, {
1055
1061
  text: `SELECT 1 FROM "information_schema"."tables" WHERE "table_name" = $1`,
@@ -1118,13 +1124,35 @@ const createExtension$1 = async (migration, up, name, options) => {
1118
1124
  }, options);
1119
1125
  let query;
1120
1126
  if (ast.action === "drop") {
1121
- query = `DROP EXTENSION${ast.ifNotExists ? " IF EXISTS" : ""} "${ast.name}"${ast.cascade ? " CASCADE" : ""}`;
1127
+ query = `DROP EXTENSION${ast.dropIfExists ? " IF EXISTS" : ""} "${ast.name}"${ast.cascade ? " CASCADE" : ""}`;
1122
1128
  } else {
1123
- query = `CREATE EXTENSION${ast.ifExists ? " IF NOT EXISTS" : ""} "${ast.name}"${ast.schema ? ` SCHEMA "${ast.schema}"` : ""}${ast.version ? ` VERSION '${ast.version}'` : ""}${ast.cascade ? " CASCADE" : ""}`;
1129
+ query = `CREATE EXTENSION${ast.createIfNotExists ? " IF NOT EXISTS" : ""} "${ast.name}"${ast.schema ? ` SCHEMA "${ast.schema}"` : ""}${ast.version ? ` VERSION '${ast.version}'` : ""}${ast.cascade ? " CASCADE" : ""}`;
1124
1130
  }
1125
1131
  await migration.adapter.query(query);
1126
1132
  await runCodeUpdater(migration, ast);
1127
1133
  };
1134
+ const createEnum = async (migration, up, name, values, options = {}) => {
1135
+ const [schema, enumName] = getSchemaAndTableFromName(name);
1136
+ const ast = __spreadValues$2({
1137
+ type: "enum",
1138
+ action: up ? "create" : "drop",
1139
+ schema,
1140
+ name: enumName,
1141
+ values
1142
+ }, options);
1143
+ let text;
1144
+ const quotedName = quoteWithSchema(ast);
1145
+ if (ast.action === "create") {
1146
+ text = `CREATE TYPE ${quotedName} AS ENUM (${values.map((_, i) => `$${i + 1}`).join(", ")})`;
1147
+ } else {
1148
+ text = `DROP TYPE${ast.dropIfExists ? " IF EXISTS" : ""} ${quotedName}${ast.cascade ? " CASCADE" : ""}`;
1149
+ }
1150
+ await migration.adapter.query({
1151
+ text,
1152
+ values
1153
+ });
1154
+ await runCodeUpdater(migration, ast);
1155
+ };
1128
1156
  const queryExists = (db, sql) => {
1129
1157
  return db.adapter.query(sql).then(({ rowCount }) => rowCount > 0);
1130
1158
  };