rake-db 2.3.44 → 2.4.0

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.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var pqb = require('pqb');
6
+ var orchidCore = require('orchid-core');
6
7
  var path = require('path');
7
8
  var promises = require('fs/promises');
8
9
  var prompts = require('prompts');
@@ -251,7 +252,7 @@ const quoteSchemaTable = ({
251
252
  schema,
252
253
  name
253
254
  }) => {
254
- return pqb.singleQuote(schema ? `${schema}.${name}` : name);
255
+ return orchidCore.singleQuote(schema ? `${schema}.${name}` : name);
255
256
  };
256
257
  const makePopulateEnumQuery = (item) => {
257
258
  const [schema, name] = getSchemaAndTableFromName(item.enumName);
@@ -308,7 +309,7 @@ const columnToSql = (key, item, values, hasMultiplePrimaryKeys) => {
308
309
  line.push("NOT NULL");
309
310
  }
310
311
  if (item.data.default !== void 0) {
311
- if (typeof item.data.default === "object" && item.data.default && pqb.isRaw(item.data.default)) {
312
+ if (typeof item.data.default === "object" && item.data.default && orchidCore.isRaw(item.data.default)) {
312
313
  line.push(`DEFAULT ${pqb.getRaw(item.data.default, values)}`);
313
314
  } else {
314
315
  line.push(`DEFAULT ${pqb.quote(item.data.default)}`);
@@ -431,7 +432,7 @@ const indexesToQuery = (up, { schema, name }, indexes) => {
431
432
  sql.push(`(${columnsSql.join(", ")})`);
432
433
  if (options.include) {
433
434
  sql.push(
434
- `INCLUDE (${pqb.toArray(options.include).map((column) => `"${column}"`).join(", ")})`
435
+ `INCLUDE (${orchidCore.toArray(options.include).map((column) => `"${column}"`).join(", ")})`
435
436
  );
436
437
  }
437
438
  if (options.with) {
@@ -442,7 +443,7 @@ const indexesToQuery = (up, { schema, name }, indexes) => {
442
443
  }
443
444
  if (options.where) {
444
445
  sql.push(
445
- `WHERE ${typeof options.where === "object" && options.where && pqb.isRaw(options.where) ? pqb.getRaw(options.where, values) : options.where}`
446
+ `WHERE ${typeof options.where === "object" && options.where && orchidCore.isRaw(options.where) ? pqb.getRaw(options.where, values) : options.where}`
446
447
  );
447
448
  }
448
449
  return { text: sql.join(" "), values };
@@ -668,10 +669,10 @@ const mergeTableData = (a, b) => {
668
669
  function add(item, options) {
669
670
  if (item instanceof pqb.ColumnType) {
670
671
  return { type: "add", item, dropMode: options == null ? void 0 : options.dropMode };
671
- } else if (item === pqb.emptyObject) {
672
+ } else if (item === orchidCore.emptyObject) {
672
673
  mergeTableData(changeTableData.add, pqb.getTableData());
673
674
  pqb.resetTableData();
674
- return pqb.emptyObject;
675
+ return orchidCore.emptyObject;
675
676
  } else {
676
677
  const result = {};
677
678
  for (const key in item) {
@@ -687,10 +688,10 @@ function add(item, options) {
687
688
  const drop = (item, options) => {
688
689
  if (item instanceof pqb.ColumnType) {
689
690
  return { type: "drop", item, dropMode: options == null ? void 0 : options.dropMode };
690
- } else if (item === pqb.emptyObject) {
691
+ } else if (item === orchidCore.emptyObject) {
691
692
  mergeTableData(changeTableData.drop, pqb.getTableData());
692
693
  pqb.resetTableData();
693
- return pqb.emptyObject;
694
+ return orchidCore.emptyObject;
694
695
  } else {
695
696
  const result = {};
696
697
  for (const key in item) {
@@ -875,7 +876,7 @@ const astToQueries = (ast) => {
875
876
  );
876
877
  }
877
878
  if (from.default !== to.default) {
878
- const value = typeof to.default === "object" && to.default && pqb.isRaw(to.default) ? pqb.getRaw(to.default, values) : pqb.quote(to.default);
879
+ const value = typeof to.default === "object" && to.default && orchidCore.isRaw(to.default) ? pqb.getRaw(to.default, values) : pqb.quote(to.default);
879
880
  const expr = value === void 0 ? "DROP DEFAULT" : `SET DEFAULT ${value}`;
880
881
  alterTable.push(`ALTER COLUMN "${key}" ${expr}`);
881
882
  }
@@ -1270,7 +1271,7 @@ const migrateOrRollback = async (options, config, args, up) => {
1270
1271
  if (!config.useCodeUpdater)
1271
1272
  delete config.appCodeUpdater;
1272
1273
  const appCodeUpdaterCache = {};
1273
- for (const opts of pqb.toArray(options)) {
1274
+ for (const opts of orchidCore.toArray(options)) {
1274
1275
  const adapter = new pqb.Adapter(opts);
1275
1276
  let db;
1276
1277
  if (up) {
@@ -1323,7 +1324,7 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
1323
1324
  try {
1324
1325
  await config.import(file.path);
1325
1326
  } catch (err) {
1326
- if (err.code === "ERR_UNSUPPORTED_ESM_URL_SCHEME")
1327
+ if (err.code !== "ERR_UNSUPPORTED_ESM_URL_SCHEME")
1327
1328
  throw err;
1328
1329
  await config.import(url__namespace.pathToFileURL(file.path).pathname);
1329
1330
  }
@@ -1432,7 +1433,7 @@ Don't use this command for database service providers, only for a local db.`;
1432
1433
  await db.close();
1433
1434
  };
1434
1435
  const createDb = async (arg, config) => {
1435
- for (const options of pqb.toArray(arg)) {
1436
+ for (const options of orchidCore.toArray(arg)) {
1436
1437
  await createOrDrop(options, options, config, {
1437
1438
  sql({ database, user }) {
1438
1439
  return `CREATE DATABASE "${database}" OWNER "${user}"`;
@@ -1448,7 +1449,7 @@ const createDb = async (arg, config) => {
1448
1449
  }
1449
1450
  };
1450
1451
  const dropDb = async (arg) => {
1451
- for (const options of pqb.toArray(arg)) {
1452
+ for (const options of orchidCore.toArray(arg)) {
1452
1453
  await createOrDrop(options, options, migrationConfigDefaults, {
1453
1454
  sql({ database }) {
1454
1455
  return `DROP DATABASE "${database}"`;
@@ -1976,7 +1977,7 @@ const getIsSerial = (item) => {
1976
1977
  if (item.type === "int2" || item.type === "int4" || item.type === "int8") {
1977
1978
  const { default: def, schemaName, tableName, name } = item;
1978
1979
  const seq = `${tableName}_${name}_seq`;
1979
- if (def && (def === `nextval(${pqb.singleQuote(`${seq}`)}::regclass)` || def === `nextval(${pqb.singleQuote(`"${seq}"`)}::regclass)` || def === `nextval(${pqb.singleQuote(`${schemaName}.${seq}`)}::regclass)` || def === `nextval(${pqb.singleQuote(`"${schemaName}".${seq}`)}::regclass)` || def === `nextval(${pqb.singleQuote(`${schemaName}."${seq}"`)}::regclass)` || def === `nextval(${pqb.singleQuote(`"${schemaName}"."${seq}"`)}::regclass)`)) {
1980
+ if (def && (def === `nextval(${orchidCore.singleQuote(`${seq}`)}::regclass)` || def === `nextval(${orchidCore.singleQuote(`"${seq}"`)}::regclass)` || def === `nextval(${orchidCore.singleQuote(`${schemaName}.${seq}`)}::regclass)` || def === `nextval(${orchidCore.singleQuote(`"${schemaName}".${seq}`)}::regclass)` || def === `nextval(${orchidCore.singleQuote(`${schemaName}."${seq}"`)}::regclass)` || def === `nextval(${orchidCore.singleQuote(`"${schemaName}"."${seq}"`)}::regclass)`)) {
1980
1981
  return true;
1981
1982
  }
1982
1983
  }
@@ -2152,47 +2153,47 @@ ${pqb.codeToString(foreignKeys, " ", " ")}
2152
2153
  return code;
2153
2154
  };
2154
2155
  const createSchema = (ast) => {
2155
- return `await db.createSchema(${pqb.singleQuote(ast.name)});`;
2156
+ return `await db.createSchema(${orchidCore.singleQuote(ast.name)});`;
2156
2157
  };
2157
2158
  const createExtension = (ast) => {
2158
- const code = [`await db.createExtension(${pqb.singleQuote(ast.name)}`];
2159
+ const code = [`await db.createExtension(${orchidCore.singleQuote(ast.name)}`];
2159
2160
  if (ast.schema || ast.version) {
2160
- pqb.addCode(code, ", {");
2161
+ orchidCore.addCode(code, ", {");
2161
2162
  if (ast.schema) {
2162
- code.push([`schema: ${pqb.singleQuote(ast.schema)},`]);
2163
+ code.push([`schema: ${orchidCore.singleQuote(ast.schema)},`]);
2163
2164
  }
2164
2165
  if (ast.version) {
2165
- code.push([`version: ${pqb.singleQuote(ast.version)},`]);
2166
+ code.push([`version: ${orchidCore.singleQuote(ast.version)},`]);
2166
2167
  }
2167
- pqb.addCode(code, "}");
2168
+ orchidCore.addCode(code, "}");
2168
2169
  }
2169
- pqb.addCode(code, ");");
2170
+ orchidCore.addCode(code, ");");
2170
2171
  return code;
2171
2172
  };
2172
2173
  const createEnum = (ast) => {
2173
2174
  const code = [
2174
- `await db.createEnum(${pqb.singleQuote(ast.name)}, [${ast.values.map(pqb.singleQuote).join(", ")}]`
2175
+ `await db.createEnum(${orchidCore.singleQuote(ast.name)}, [${ast.values.map(orchidCore.singleQuote).join(", ")}]`
2175
2176
  ];
2176
2177
  if (ast.schema) {
2177
- pqb.addCode(code, ", {");
2178
- code.push([`schema: ${pqb.singleQuote(ast.schema)},`]);
2179
- pqb.addCode(code, "}");
2178
+ orchidCore.addCode(code, ", {");
2179
+ code.push([`schema: ${orchidCore.singleQuote(ast.schema)},`]);
2180
+ orchidCore.addCode(code, "}");
2180
2181
  }
2181
- pqb.addCode(code, ");");
2182
+ orchidCore.addCode(code, ");");
2182
2183
  return code;
2183
2184
  };
2184
2185
  const createTable = (ast) => {
2185
2186
  const code = [];
2186
- pqb.addCode(code, `await db.createTable(${quoteSchemaTable(ast)}, (t) => ({`);
2187
+ orchidCore.addCode(code, `await db.createTable(${quoteSchemaTable(ast)}, (t) => ({`);
2187
2188
  const hasTimestamps = isTimestamp(ast.shape.createdAt) && isTimestamp(ast.shape.updatedAt);
2188
2189
  for (const key in ast.shape) {
2189
2190
  if (hasTimestamps && (key === "createdAt" || key === "updatedAt"))
2190
2191
  continue;
2191
- const line = [`${pqb.quoteObjectKey(key)}: `];
2192
+ const line = [`${orchidCore.quoteObjectKey(key)}: `];
2192
2193
  for (const part of ast.shape[key].toCode("t")) {
2193
- pqb.addCode(line, part);
2194
+ orchidCore.addCode(line, part);
2194
2195
  }
2195
- pqb.addCode(line, ",");
2196
+ orchidCore.addCode(line, ",");
2196
2197
  code.push(line);
2197
2198
  }
2198
2199
  if (hasTimestamps) {
@@ -2207,14 +2208,14 @@ const createTable = (ast) => {
2207
2208
  for (const foreignKey of ast.foreignKeys) {
2208
2209
  code.push(pqb.foreignKeyToCode(foreignKey, "t"));
2209
2210
  }
2210
- pqb.addCode(code, "}));");
2211
+ orchidCore.addCode(code, "}));");
2211
2212
  return code;
2212
2213
  };
2213
2214
  const isTimestamp = (column) => {
2214
2215
  if (!column)
2215
2216
  return false;
2216
2217
  const { default: def } = column.data;
2217
- return column instanceof pqb.TimestampColumn && !column.data.isNullable && def && typeof def === "object" && pqb.isRaw(def) && def.__raw === "now()";
2218
+ return column instanceof pqb.TimestampColumn && !column.data.isNullable && def && typeof def === "object" && orchidCore.isRaw(def) && def.__raw === "now()";
2218
2219
  };
2219
2220
  const createForeignKey = (item) => {
2220
2221
  return [
@@ -2259,9 +2260,9 @@ const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2))
2259
2260
  } else if (command === "g" || command === "generate") {
2260
2261
  await generate(config, args.slice(1));
2261
2262
  } else if (command === "pull") {
2262
- await pullDbStructure(pqb.toArray(options)[0], config);
2263
+ await pullDbStructure(orchidCore.toArray(options)[0], config);
2263
2264
  } else if (config.commands[command]) {
2264
- await config.commands[command](pqb.toArray(options), config, args.slice(1));
2265
+ await config.commands[command](orchidCore.toArray(options), config, args.slice(1));
2265
2266
  } else {
2266
2267
  printHelp();
2267
2268
  }