@lark-apaas/db-schema-sync 0.1.17 → 0.1.18

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/bin.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  __toESM,
7
7
  generateSchema,
8
8
  resolveEnvOptions
9
- } from "./chunk-ACLG7GQP.js";
9
+ } from "./chunk-7O4DEVTQ.js";
10
10
 
11
11
  // node_modules/dotenv/package.json
12
12
  var require_package = __commonJS({
@@ -1863,17 +1863,19 @@ function generateEnumCode(schema) {
1863
1863
  }
1864
1864
 
1865
1865
  // src/generator/structures/index-gen.ts
1866
- function generateIndexCode(idx, tableIdentifier) {
1866
+ function generateIndexCode(idx, tableIdentifier, knownColumnProperties) {
1867
1867
  const fn = idx.indexType === "unique" ? "uniqueIndex" : "index";
1868
- const columns = idx.indexColumns.map((col) => `table.${sanitizePropertyName(col)}`).join(", ");
1868
+ const propertyRefs = idx.indexColumns.map((col) => sanitizePropertyName(col));
1869
+ const columns = propertyRefs.map((prop) => `table.${prop}`).join(", ");
1869
1870
  const escapedName = escapeDoubleQuote(idx.indexName);
1871
+ const allColumnsKnown = knownColumnProperties === void 0 ? true : propertyRefs.every((prop) => knownColumnProperties.has(prop));
1872
+ if (!columns || !allColumnsKnown) {
1873
+ return `// Complex index: ${idx.indexDef || idx.indexName}`;
1874
+ }
1870
1875
  const creationType = idx.indexCreationType || "btree";
1871
- if (creationType !== "btree" && columns) {
1876
+ if (creationType !== "btree") {
1872
1877
  return `${fn}("${escapedName}").using("${creationType}", ${columns})`;
1873
1878
  }
1874
- if (!columns) {
1875
- return `// Complex index: ${idx.indexDef || idx.indexName}`;
1876
- }
1877
1879
  return `${fn}("${escapedName}").on(${columns})`;
1878
1880
  }
1879
1881
 
@@ -1899,16 +1901,18 @@ function generateForeignKeyCode(rel, tableIdentifier, tableIdentifierMap) {
1899
1901
 
1900
1902
  // src/generator/structures/table.ts
1901
1903
  function generateTableCode(table, schemaData, registry, modifiers, tableIdentifierMap) {
1904
+ const knownColumnProperties = /* @__PURE__ */ new Set();
1902
1905
  const fieldLines = table.fields.map((field) => {
1903
1906
  const mapper = registry.resolve(field);
1904
1907
  const typeExpr = mapper.generate(field);
1905
1908
  const mods = applyModifiers(field, modifiers);
1906
1909
  const propName = sanitizePropertyName(field.fieldName);
1910
+ knownColumnProperties.add(propName);
1907
1911
  return ` ${propName}: ${typeExpr}${mods},`;
1908
1912
  });
1909
1913
  const thirdArgParts = [];
1910
1914
  for (const idx of table.indexes) {
1911
- thirdArgParts.push(generateIndexCode(idx, table.identifier));
1915
+ thirdArgParts.push(generateIndexCode(idx, table.identifier, knownColumnProperties));
1912
1916
  }
1913
1917
  for (const rel of table.relationships) {
1914
1918
  thirdArgParts.push(generateForeignKeyCode(rel, table.identifier, tableIdentifierMap));
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  generateSchemaFromData,
6
6
  normalizeApiResponse,
7
7
  resolveEnvOptions
8
- } from "./chunk-ACLG7GQP.js";
8
+ } from "./chunk-7O4DEVTQ.js";
9
9
  export {
10
10
  generateSchema,
11
11
  generateSchemaCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/db-schema-sync",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",