rake-db 2.33.2 → 2.33.3

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
@@ -63,7 +63,7 @@ const makePopulateEnumQuery = (schema, item) => {
63
63
  };
64
64
  const transaction = (adapter, config, fn) => {
65
65
  const searchPath = config.transactionSearchPath;
66
- return adapter.transaction(searchPath ? { locals: { search_path: typeof searchPath === "function" ? searchPath() : searchPath } } : void 0, fn);
66
+ return adapter.transaction(void 0, searchPath ? { setConfig: { search_path: typeof searchPath === "function" ? searchPath() : searchPath } } : void 0, fn);
67
67
  };
68
68
  const queryLock = (trx) => trx.query(`SELECT pg_advisory_xact_lock('${RAKE_DB_LOCK_KEY}')`);
69
69
  const getCliParam = (args, name) => {
@@ -1039,7 +1039,9 @@ const astToQuery = (ast) => {
1039
1039
  w.push(serializers[key](value));
1040
1040
  }
1041
1041
  }
1042
- let sql = `${ast.action.toUpperCase()} ROLE "${ast.name}"${w.length ? ` WITH ${w.join(" ")}` : ""}`;
1042
+ const escapedRoleName = ast.name.replace(/'/g, "''");
1043
+ const roleSql = `${ast.action.toUpperCase()} ROLE "${ast.name}"${w.length ? ` WITH ${w.join(" ")}` : ""}`;
1044
+ let sql = ast.action === "create" ? `DO $$\nBEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${escapedRoleName}') THEN\n ${roleSql};\n END IF;\nEND\n$$` : roleSql;
1043
1045
  if (ast.action !== "drop" && ast.config) for (const [key, value] of Object.entries(ast.config)) sql += `;\nALTER ROLE "${ast.name}" SET ${key} = '${value}'`;
1044
1046
  return sql;
1045
1047
  };
@@ -3196,7 +3198,7 @@ const createOrDropDatabase = async (action, adapters, config, dontClose) => {
3196
3198
  askAdminCreds: () => askForAdminCredentials(action === "create")
3197
3199
  })) continue;
3198
3200
  if (action === "create") {
3199
- await adapter.transaction(async (tx) => {
3201
+ await adapter.transaction(void 0, void 0, async (tx) => {
3200
3202
  const schema = adapter.getSchema();
3201
3203
  if (schema) {
3202
3204
  const quoted = `"${typeof schema === "function" ? schema() : schema}"`;