rake-db 2.10.45 → 2.10.47

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
@@ -383,14 +383,9 @@ const columnToSql = (name, item, values, hasMultiplePrimaryKeys, snakeCase) => {
383
383
  if (item.data.check) {
384
384
  line.push(checkToSql(item.data.check, values));
385
385
  }
386
- const def = item.data.default;
387
- if (def !== void 0 && def !== null && typeof def !== "function") {
388
- if (orchidCore.isRawSQL(def)) {
389
- line.push(`DEFAULT ${def.toSQL({ values })}`);
390
- } else {
391
- line.push(`DEFAULT ${pqb.quote(def)}`);
392
- }
393
- }
386
+ const def = encodeColumnDefault(item.data.default, values, item);
387
+ if (def !== null)
388
+ line.push(`DEFAULT ${def}`);
394
389
  const { foreignKeys } = item.data;
395
390
  if (foreignKeys) {
396
391
  for (const foreignKey of foreignKeys) {
@@ -412,6 +407,16 @@ const columnToSql = (name, item, values, hasMultiplePrimaryKeys, snakeCase) => {
412
407
  }
413
408
  return line.join(" ");
414
409
  };
410
+ const encodeColumnDefault = (def, values, column) => {
411
+ if (def !== void 0 && def !== null && typeof def !== "function") {
412
+ if (orchidCore.isRawSQL(def)) {
413
+ return def.toSQL({ values });
414
+ } else {
415
+ return pqb.quote((column == null ? void 0 : column.encodeFn) ? column.encodeFn(def) : def);
416
+ }
417
+ }
418
+ return null;
419
+ };
415
420
  const identityToSql = (identity) => {
416
421
  const options = sequenceOptionsToSql(identity);
417
422
  return `GENERATED ${identity.always ? "ALWAYS" : "BY DEFAULT"} AS IDENTITY${options ? ` (${options})` : ""}`;
@@ -1146,7 +1151,7 @@ const astToQueries = (ast, snakeCase, language) => {
1146
1151
  );
1147
1152
  }
1148
1153
  if (from.default !== to.default) {
1149
- const value = to.default === void 0 || to.default === null || typeof to.default === "function" ? null : typeof to.default === "object" && orchidCore.isRawSQL(to.default) ? to.default.toSQL({ values }) : pqb.quote(to.default);
1154
+ const value = encodeColumnDefault(to.default, values, to.column);
1150
1155
  if (changeType && value !== null) {
1151
1156
  alterTable.push(`ALTER COLUMN "${name}" DROP DEFAULT`);
1152
1157
  }