rake-db 2.10.3 → 2.10.5

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
@@ -1085,7 +1085,9 @@ const astToQueries = (ast, snakeCase, language) => {
1085
1085
  } else if (item.type === "change") {
1086
1086
  const { from, to } = item;
1087
1087
  const name = getChangeColumnName(item, key, snakeCase);
1088
+ let changeType = false;
1088
1089
  if (to.type && (from.type !== to.type || from.collate !== to.collate)) {
1090
+ changeType = true;
1089
1091
  const type = !to.column || to.column.data.isOfCustomType ? `"${to.type}"` : to.type;
1090
1092
  alterTable.push(
1091
1093
  `ALTER COLUMN "${name}" TYPE ${type}${to.collate ? ` COLLATE ${quoteNameFromString(to.collate)}` : ""}${item.using ? ` USING ${item.using.toSQL({ values })}` : ""}`
@@ -1097,7 +1099,10 @@ const astToQueries = (ast, snakeCase, language) => {
1097
1099
  );
1098
1100
  }
1099
1101
  if (from.default !== to.default) {
1100
- const value = typeof to.default === "object" && to.default && orchidCore.isRawSQL(to.default) ? to.default.toSQL({ values }) : pqb.quote(to.default);
1102
+ const value = to.default === void 0 ? void 0 : typeof to.default === "object" && to.default && orchidCore.isRawSQL(to.default) ? to.default.toSQL({ values }) : pqb.quote(to.default);
1103
+ if (changeType && value !== void 0) {
1104
+ alterTable.push(`ALTER COLUMN "${name}" DROP DEFAULT`);
1105
+ }
1101
1106
  const expr = value === void 0 ? "DROP DEFAULT" : `SET DEFAULT ${value}`;
1102
1107
  alterTable.push(`ALTER COLUMN "${name}" ${expr}`);
1103
1108
  }