rake-db 2.22.34 → 2.22.36

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.d.ts CHANGED
@@ -1727,6 +1727,7 @@ declare const commentsToQuery: (schemaTable: {
1727
1727
  name: string;
1728
1728
  }, comments: ColumnComment[]) => SingleSql[];
1729
1729
  declare const primaryKeyToSql: (primaryKey: Exclude<TableData['primaryKey'], undefined>) => string;
1730
+ declare const interpolateSqlValues: ({ text, values }: TableQuery) => string;
1730
1731
 
1731
1732
  /**
1732
1733
  * Type of {@link rakeDb} function
@@ -1812,4 +1813,4 @@ declare const promptText: ({ message, default: def, password, min, }: {
1812
1813
  min?: number;
1813
1814
  }) => Promise<string>;
1814
1815
 
1815
- export { AnyRakeDbConfig, ChangeCallback, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, CommandFn, DbMigration, DbStructure, DbStructureDomainsMap, DropMode, InputRakeDbConfig, InputRakeDbConfigBase, IntrospectedStructure, Migration, MigrationAdapter, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAppliedVersions, RakeDbAst, RakeDbBaseTable, RakeDbChangeFn, RakeDbConfig, RakeDbCtx, RakeDbFn, RakeDbFnReturns, RakeDbLazyFn, RakeDbMigrationId, RakeDbRenameMigrations, RakeDbRenameMigrationsInput, RakeDbRenameMigrationsMap, RakeDbResult, SilentQueries, StructureToAstCtx, StructureToAstTableData, TableOptions, addColumnComment, addColumnIndex, addOrDropEnumValues, astToMigration, changeCache, changeEnumValues, clearChanges, colors, columnToSql, columnTypeToSql, commentsToQuery, concatSchemaAndName, constraintToSql, createDb, createMigrationInterface, dbColumnToAst, deleteMigratedVersion, dropDb, encodeColumnDefault, exhaustive, generateTimeStamp, getColumnName, getConstraintName, getCurrentChanges, getDatabaseAndUserFromOptions, getDbStructureTableData, getDbTableColumnsChecks, getFirstWordAndRest, getForeignKeyTable, getIndexName, getMigratedVersionsMap, getSchemaAndTableFromName, getTextAfterFrom, getTextAfterTo, identityToSql, indexesToQuery, instantiateDbColumn, introspectDbSchema, joinColumns, joinWords, makeDbStructureColumnsShape, makeDomainsMap, makeFileVersion, makePopulateEnumQuery, makeStructureToAstCtx, migrate, migrateOrRollback, migrationConfigDefaults, newMigration, pluralize, primaryKeyToSql, processRakeDbConfig, promptConfirm, promptSelect, promptText, pushChange, queryLock, quoteNameFromString, quoteSchemaTable, quoteTable, quoteWithSchema, rakeDb, rakeDbAliases, rakeDbCommands, redo, referencesToSql, renameType, resetDb, rollback, saveMigratedVersion, structureToAst, tableToAst, transaction, versionToString, writeMigrationFile };
1816
+ export { AnyRakeDbConfig, ChangeCallback, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, CommandFn, DbMigration, DbStructure, DbStructureDomainsMap, DropMode, InputRakeDbConfig, InputRakeDbConfigBase, IntrospectedStructure, Migration, MigrationAdapter, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAppliedVersions, RakeDbAst, RakeDbBaseTable, RakeDbChangeFn, RakeDbConfig, RakeDbCtx, RakeDbFn, RakeDbFnReturns, RakeDbLazyFn, RakeDbMigrationId, RakeDbRenameMigrations, RakeDbRenameMigrationsInput, RakeDbRenameMigrationsMap, RakeDbResult, SilentQueries, StructureToAstCtx, StructureToAstTableData, TableOptions, addColumnComment, addColumnIndex, addOrDropEnumValues, astToMigration, changeCache, changeEnumValues, clearChanges, colors, columnToSql, columnTypeToSql, commentsToQuery, concatSchemaAndName, constraintToSql, createDb, createMigrationInterface, dbColumnToAst, deleteMigratedVersion, dropDb, encodeColumnDefault, exhaustive, generateTimeStamp, getColumnName, getConstraintName, getCurrentChanges, getDatabaseAndUserFromOptions, getDbStructureTableData, getDbTableColumnsChecks, getFirstWordAndRest, getForeignKeyTable, getIndexName, getMigratedVersionsMap, getSchemaAndTableFromName, getTextAfterFrom, getTextAfterTo, identityToSql, indexesToQuery, instantiateDbColumn, interpolateSqlValues, introspectDbSchema, joinColumns, joinWords, makeDbStructureColumnsShape, makeDomainsMap, makeFileVersion, makePopulateEnumQuery, makeStructureToAstCtx, migrate, migrateOrRollback, migrationConfigDefaults, newMigration, pluralize, primaryKeyToSql, processRakeDbConfig, promptConfirm, promptSelect, promptText, pushChange, queryLock, quoteNameFromString, quoteSchemaTable, quoteTable, quoteWithSchema, rakeDb, rakeDbAliases, rakeDbCommands, redo, referencesToSql, renameType, resetDb, rollback, saveMigratedVersion, structureToAst, tableToAst, transaction, versionToString, writeMigrationFile };
package/dist/index.js CHANGED
@@ -175,7 +175,7 @@ const encodeColumnDefault = (def, values, column) => {
175
175
  if (orchidCore.isRawSQL(def)) {
176
176
  return def.toSQL({ values });
177
177
  } else {
178
- return pqb.quote((column == null ? void 0 : column.encodeFn) ? column.encodeFn(def) : def);
178
+ return pqb.escapeForMigration((column == null ? void 0 : column.encodeFn) ? column.encodeFn(def) : def);
179
179
  }
180
180
  }
181
181
  return null;
@@ -373,13 +373,19 @@ const commentsToQuery = (schemaTable, comments) => {
373
373
  return comments.map(({ column, comment }) => ({
374
374
  text: `COMMENT ON COLUMN ${quoteWithSchema(
375
375
  schemaTable
376
- )}."${column}" IS ${pqb.quote(comment)}`,
376
+ )}."${column}" IS ${pqb.escapeForMigration(comment)}`,
377
377
  values: []
378
378
  }));
379
379
  };
380
380
  const primaryKeyToSql = (primaryKey) => {
381
381
  return `${primaryKey.name ? `CONSTRAINT "${primaryKey.name}" ` : ""}PRIMARY KEY (${joinColumns(primaryKey.columns)})`;
382
382
  };
383
+ const interpolateSqlValues = ({ text, values }) => {
384
+ return (values == null ? void 0 : values.length) ? text.replace(/\$(\d+)/g, (_, n) => {
385
+ const i = +n - 1;
386
+ return pqb.escapeForMigration(values[i]);
387
+ }) : text;
388
+ };
383
389
 
384
390
  const tableMethods = {
385
391
  enum(name) {
@@ -474,7 +480,7 @@ const createTable = async (migration, up, tableName, first, second, third) => {
474
480
  const queries = astToQueries$1(ast, snakeCase, language);
475
481
  for (const _b of queries) {
476
482
  const _c = _b, { then } = _c, query = __objRest$1(_c, ["then"]);
477
- const result = await migration.adapter.arrays(query);
483
+ const result = await migration.adapter.arrays(interpolateSqlValues(query));
478
484
  then == null ? void 0 : then(result);
479
485
  }
480
486
  let table;
@@ -618,7 +624,9 @@ const astToQueries$1 = (ast, snakeCase, language) => {
618
624
  );
619
625
  if (ast.comment) {
620
626
  queries.push({
621
- text: `COMMENT ON TABLE ${quoteWithSchema(ast)} IS ${pqb.quote(ast.comment)}`
627
+ text: `COMMENT ON TABLE ${quoteWithSchema(ast)} IS ${pqb.escapeString(
628
+ ast.comment
629
+ )}`
622
630
  });
623
631
  }
624
632
  return queries;
@@ -851,7 +859,7 @@ const changeTable = async (migration, up, tableName, options, fn) => {
851
859
  const ast = makeAst$1(up, tableName, changeData, changeTableData, options);
852
860
  const queries = astToQueries(ast, snakeCase, language);
853
861
  for (const query of queries) {
854
- const result = await migration.adapter.arrays(query);
862
+ const result = await migration.adapter.arrays(interpolateSqlValues(query));
855
863
  (_a = query.then) == null ? void 0 : _a.call(query, result);
856
864
  }
857
865
  };
@@ -914,7 +922,9 @@ const astToQueries = (ast, snakeCase, language) => {
914
922
  const queries = [];
915
923
  if (ast.comment !== void 0) {
916
924
  queries.push({
917
- text: `COMMENT ON TABLE ${quoteWithSchema(ast)} IS ${pqb.quote(ast.comment)}`
925
+ text: `COMMENT ON TABLE ${quoteWithSchema(ast)} IS ${ast.comment === null ? "NULL" : pqb.escapeString(
926
+ typeof ast.comment === "string" ? ast.comment : ast.comment[1]
927
+ )}`
918
928
  });
919
929
  }
920
930
  const addPrimaryKeys = {
@@ -1255,7 +1265,7 @@ const renameColumnSql = (from, to) => {
1255
1265
  const createView = async (migration, up, name, options, sql) => {
1256
1266
  const ast = makeAst(up, name, options, sql);
1257
1267
  const query = astToQuery(ast);
1258
- await migration.adapter.query(query);
1268
+ await migration.adapter.arrays(interpolateSqlValues(query));
1259
1269
  };
1260
1270
  const makeAst = (up, name, options, sql) => {
1261
1271
  if (typeof sql === "string") {
@@ -2261,7 +2271,7 @@ const createEnum = async (migration, up, name, values, options = {}) => {
2261
2271
  let query;
2262
2272
  const quotedName = quoteWithSchema(ast);
2263
2273
  if (ast.action === "create") {
2264
- query = `CREATE TYPE ${quotedName} AS ENUM (${values.map(pqb.quote).join(", ")})`;
2274
+ query = `CREATE TYPE ${quotedName} AS ENUM (${values.map(pqb.escapeForMigration).join(", ")})`;
2265
2275
  } else {
2266
2276
  query = `DROP TYPE${ast.dropIfExists ? " IF EXISTS" : ""} ${quotedName}${ast.cascade ? " CASCADE" : ""}`;
2267
2277
  }
@@ -2290,10 +2300,12 @@ DEFAULT ${encodeColumnDefault(column.data.default, values)}` : ""}${!column.data
2290
2300
  } else {
2291
2301
  query = `DROP DOMAIN ${quotedName}`;
2292
2302
  }
2293
- await migration.adapter.query({
2294
- text: query,
2295
- values
2296
- });
2303
+ await migration.adapter.query(
2304
+ interpolateSqlValues({
2305
+ text: query,
2306
+ values
2307
+ })
2308
+ );
2297
2309
  };
2298
2310
  const createCollation = async (migration, up, name, options) => {
2299
2311
  const [schema, collationName] = getSchemaAndTableFromName(name);
@@ -2330,9 +2342,7 @@ const createCollation = async (migration, up, name, options) => {
2330
2342
  } else {
2331
2343
  query = `DROP COLLATION${ast.dropIfExists ? " IF EXISTS" : ""} ${quotedName}${ast.cascade ? ` CASCADE` : ""}`;
2332
2344
  }
2333
- await migration.adapter.query({
2334
- text: query
2335
- });
2345
+ await migration.adapter.query(query);
2336
2346
  };
2337
2347
  const queryExists = (db, sql) => {
2338
2348
  return db.adapter.query(sql).then(({ rowCount }) => rowCount > 0);
@@ -5935,6 +5945,7 @@ exports.getTextAfterTo = getTextAfterTo;
5935
5945
  exports.identityToSql = identityToSql;
5936
5946
  exports.indexesToQuery = indexesToQuery;
5937
5947
  exports.instantiateDbColumn = instantiateDbColumn;
5948
+ exports.interpolateSqlValues = interpolateSqlValues;
5938
5949
  exports.introspectDbSchema = introspectDbSchema;
5939
5950
  exports.joinColumns = joinColumns;
5940
5951
  exports.joinWords = joinWords;