orchid-orm 1.4.21 → 1.4.22

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
@@ -1754,7 +1754,11 @@ const createTable = async (_a) => {
1754
1754
  ]);
1755
1755
  const tablePath = params.tablePath(ast.name);
1756
1756
  const baseTablePath = getImportPath(tablePath, params.baseTablePath);
1757
- const props = [`table = ${pqb.singleQuote(ast.name)};`];
1757
+ const props = [];
1758
+ if (ast.schema) {
1759
+ props.push(`schema = ${pqb.singleQuote(ast.schema)};`);
1760
+ }
1761
+ props.push(`table = ${pqb.singleQuote(ast.name)};`);
1758
1762
  if (ast.noPrimaryKey === "ignore") {
1759
1763
  props.push("noPrimaryKey = true;");
1760
1764
  }
@@ -2197,17 +2201,38 @@ const renameTable = async (_a) => {
2197
2201
  const changes = new FileChanges(content);
2198
2202
  const statements = ts.getStatements(content);
2199
2203
  const className = toPascalCase(ast.from);
2204
+ const changeSchema = ast.fromSchema !== ast.toSchema;
2200
2205
  for (const node of ts.class.iterate(statements)) {
2201
2206
  if (((_a2 = node.name) == null ? void 0 : _a2.escapedText) !== className)
2202
2207
  continue;
2208
+ const addSchema = changeSchema && ast.toSchema && !node.members.some((member) => ts.prop.getName(member) === "schema");
2209
+ if (addSchema && ast.toSchema) {
2210
+ changes.add(
2211
+ node.members.pos,
2212
+ `
2213
+ schema = ${pqb.singleQuote(ast.toSchema)};`
2214
+ );
2215
+ }
2203
2216
  for (const member of node.members) {
2204
2217
  const name = ts.prop.getName(member);
2205
- if (name !== "table")
2218
+ if (name !== "table" && !(changeSchema && name === "schema"))
2206
2219
  continue;
2207
2220
  const { initializer: value } = member;
2208
2221
  if (!value)
2209
2222
  continue;
2210
- changes.replace(value.pos, value.end, ` ${pqb.singleQuote(ast.to)}`);
2223
+ if (name === "schema") {
2224
+ if (ast.toSchema) {
2225
+ changes.replace(
2226
+ value.pos,
2227
+ value.end,
2228
+ ` ${pqb.singleQuote(ast.toSchema)}`
2229
+ );
2230
+ } else {
2231
+ changes.remove(member.pos, member.end);
2232
+ }
2233
+ } else {
2234
+ changes.replace(value.pos, value.end, ` ${pqb.singleQuote(ast.to)}`);
2235
+ }
2211
2236
  }
2212
2237
  }
2213
2238
  await fs__default["default"].writeFile(params.tablePath(ast.to), changes.apply());