imean-cassandra-orm 3.0.0 → 3.0.2

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.
Files changed (3) hide show
  1. package/dist/mod.cjs +66 -34
  2. package/dist/mod.js +66 -34
  3. package/package.json +1 -1
package/dist/mod.cjs CHANGED
@@ -1527,10 +1527,12 @@ var Model = class _Model {
1527
1527
  // 同步 Schema
1528
1528
  async syncSchema(force = false) {
1529
1529
  try {
1530
+ console.log(`\u{1F504} \u5F00\u59CB\u540C\u6B65\u8868: ${this.schema.keyspace}.${this.schema.tableName}`);
1530
1531
  const operations = await this.syncTableSchema(force);
1532
+ console.log(`\u2705 \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5B8C\u6210`);
1531
1533
  return operations.join("\n");
1532
1534
  } catch (error) {
1533
- console.error("\u540C\u6B65\u8868\u7ED3\u6784\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1535
+ console.error(`\u274C \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5931\u8D25:`, error);
1534
1536
  throw error;
1535
1537
  }
1536
1538
  }
@@ -1538,6 +1540,12 @@ var Model = class _Model {
1538
1540
  async syncTableSchema(forceRecreate = false) {
1539
1541
  const operations = [];
1540
1542
  try {
1543
+ console.log(` \u{1F4CB} \u8868\u7ED3\u6784: ${this.schema.keyspace}.${this.schema.tableName}`);
1544
+ console.log(` \u{1F511} \u5206\u533A\u952E: [${this.schema.partitionKey.join(", ")}]`);
1545
+ if (this.schema.clusteringKey) {
1546
+ console.log(` \u{1F4CA} \u805A\u7C7B\u952E: ${Object.entries(this.schema.clusteringKey).map(([k, v]) => `${k}:${v}`).join(", ")}`);
1547
+ }
1548
+ console.log(` \u{1F4DD} \u5B57\u6BB5\u6570\u91CF: ${Object.keys(this.schema.fields.shape).length}`);
1541
1549
  await this.client.execute(
1542
1550
  queryHelper.ensureKeyspace(
1543
1551
  this.schema.keyspace,
@@ -1551,10 +1559,11 @@ var Model = class _Model {
1551
1559
  operations.push(...indexQueries);
1552
1560
  } else {
1553
1561
  const tableChanges = await this.analyzeTableChanges();
1554
- const hasUnalterableChanges = tableChanges.some(
1555
- (op) => op.startsWith("DROP TABLE")
1556
- );
1562
+ const hasUnalterableChanges = tableChanges.unalterableReasons.length > 0;
1557
1563
  if (forceRecreate && hasUnalterableChanges) {
1564
+ console.log("\u68C0\u6D4B\u5230\u4E0D\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u91CD\u5EFA\u8868");
1565
+ console.log("\u4E0D\u53EF\u53D8\u66F4\u539F\u56E0:", tableChanges.unalterableReasons);
1566
+ console.log("\u6240\u6709\u53D8\u66F4:", tableChanges.changes);
1558
1567
  operations.push(
1559
1568
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1560
1569
  );
@@ -1562,15 +1571,23 @@ var Model = class _Model {
1562
1571
  const indexQueries = queryHelper.createIndexes(this.schema);
1563
1572
  operations.push(...indexQueries);
1564
1573
  } else if (forceRecreate && !hasUnalterableChanges) {
1565
- operations.push(...tableChanges);
1574
+ console.log("\u68C0\u6D4B\u5230\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u4F7F\u7528 ALTER TABLE");
1575
+ console.log("\u53D8\u66F4\u8BE6\u60C5:", tableChanges.changes);
1576
+ operations.push(...tableChanges.operations);
1566
1577
  const indexOperations = await this.syncIndexes();
1567
1578
  operations.push(...indexOperations);
1568
1579
  } else if (!forceRecreate && hasUnalterableChanges) {
1580
+ const reasons = tableChanges.unalterableReasons.join("; ");
1569
1581
  throw new Error(
1570
- `\u8868\u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A\u4E3B\u952E\u53D8\u66F4\u3001\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\u7B49\u3002`
1582
+ `\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
1583
+ \u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A
1584
+ ${reasons}
1585
+ \u5176\u4ED6\u53D8\u66F4\uFF1A${tableChanges.changes.join("; ")}`
1571
1586
  );
1572
1587
  } else {
1573
- operations.push(...tableChanges);
1588
+ console.log("\u68C0\u6D4B\u5230\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u4F7F\u7528 ALTER TABLE");
1589
+ console.log("\u53D8\u66F4\u8BE6\u60C5:", tableChanges.changes);
1590
+ operations.push(...tableChanges.operations);
1574
1591
  const indexOperations = await this.syncIndexes();
1575
1592
  operations.push(...indexOperations);
1576
1593
  }
@@ -1599,6 +1616,8 @@ var Model = class _Model {
1599
1616
  // 分析表结构变更
1600
1617
  async analyzeTableChanges() {
1601
1618
  const operations = [];
1619
+ const changes = [];
1620
+ const unalterableReasons = [];
1602
1621
  try {
1603
1622
  const tableMetadata2 = await this.client.execute(queryHelper.tableMetadata(), [
1604
1623
  this.schema.keyspace,
@@ -1607,34 +1626,44 @@ var Model = class _Model {
1607
1626
  const schemaFields = Object.keys(this.schema.fields.shape);
1608
1627
  const newFields = this.getNewFields(schemaFields, tableMetadata2);
1609
1628
  const deletedFields = this.getDeletedFields(schemaFields, tableMetadata2);
1610
- const hasPrimaryKeyChanges = await this.checkPrimaryKeyChanges();
1611
- if (hasPrimaryKeyChanges) {
1629
+ if (newFields.length > 0) {
1630
+ changes.push(`\u65B0\u589E\u5B57\u6BB5: ${newFields.join(", ")}`);
1631
+ operations.push(queryHelper.addColumns(this.schema, newFields));
1632
+ }
1633
+ if (deletedFields.length > 0) {
1634
+ changes.push(`\u5220\u9664\u5B57\u6BB5: ${deletedFields.join(", ")}`);
1635
+ operations.push(queryHelper.dropColumns(this.schema, deletedFields));
1636
+ }
1637
+ const primaryKeyChanges = await this.checkPrimaryKeyChanges();
1638
+ if (primaryKeyChanges.hasChanges) {
1639
+ unalterableReasons.push(
1640
+ `\u4E3B\u952E\u53D8\u66F4: ${primaryKeyChanges.reasons.join(", ")}`
1641
+ );
1612
1642
  operations.push(
1613
1643
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1614
1644
  );
1615
1645
  operations.push(queryHelper.createTable(this.schema));
1616
- return operations;
1646
+ const indexQueries = queryHelper.createIndexes(this.schema);
1647
+ operations.push(...indexQueries);
1617
1648
  }
1618
- const hasTypeChanges = await this.checkFieldTypeChanges(tableMetadata2);
1619
- if (hasTypeChanges) {
1649
+ const typeChanges = await this.checkFieldTypeChanges(tableMetadata2);
1650
+ if (typeChanges.hasChanges) {
1651
+ unalterableReasons.push(
1652
+ `\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${typeChanges.reasons.join(", ")}`
1653
+ );
1620
1654
  operations.push(
1621
1655
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1622
1656
  );
1623
1657
  operations.push(queryHelper.createTable(this.schema));
1624
- return operations;
1625
- }
1626
- if (newFields.length > 0) {
1627
- const addQuery = queryHelper.addColumns(this.schema, newFields);
1628
- operations.push(addQuery);
1629
- }
1630
- if (deletedFields.length > 0) {
1631
- const dropQuery = queryHelper.dropColumns(this.schema, deletedFields);
1632
- operations.push(dropQuery);
1658
+ const indexQueries = queryHelper.createIndexes(this.schema);
1659
+ operations.push(...indexQueries);
1633
1660
  }
1661
+ const indexOperations = await this.syncIndexes();
1662
+ operations.push(...indexOperations);
1663
+ return { operations, changes, unalterableReasons };
1634
1664
  } catch (error) {
1635
- console.error("\u5206\u6790\u8868\u7ED3\u6784\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1665
+ throw new Error(`\u5206\u6790\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
1636
1666
  }
1637
- return operations;
1638
1667
  }
1639
1668
  // 智能同步索引
1640
1669
  async syncIndexes() {
@@ -1675,7 +1704,7 @@ var Model = class _Model {
1675
1704
  [this.schema.keyspace, this.schema.tableName]
1676
1705
  );
1677
1706
  if (partitionKeyResult.rows.length !== this.schema.partitionKey.length) {
1678
- return true;
1707
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u6570\u91CF\u4E0D\u4E00\u81F4"] };
1679
1708
  }
1680
1709
  const existingPartitionKeys = new Set(
1681
1710
  partitionKeyResult.rows.map((row) => row.column_name.toLowerCase())
@@ -1684,11 +1713,11 @@ var Model = class _Model {
1684
1713
  this.schema.partitionKey.map((key) => String(key).toLowerCase())
1685
1714
  );
1686
1715
  if (existingPartitionKeys.size !== schemaPartitionKeys.size) {
1687
- return true;
1716
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u5B57\u6BB5\u540D\u4E0D\u4E00\u81F4"] };
1688
1717
  }
1689
1718
  for (const key of existingPartitionKeys) {
1690
1719
  if (!schemaPartitionKeys.has(key)) {
1691
- return true;
1720
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u5B57\u6BB5\u540D\u4E0D\u4E00\u81F4"] };
1692
1721
  }
1693
1722
  }
1694
1723
  if (this.schema.clusteringKey) {
@@ -1701,20 +1730,20 @@ var Model = class _Model {
1701
1730
  Object.keys(this.schema.clusteringKey).map((key) => key.toLowerCase())
1702
1731
  );
1703
1732
  if (existingClusteringKeys.size !== schemaClusteringKeys.size) {
1704
- return true;
1733
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1705
1734
  }
1706
1735
  for (const key of existingClusteringKeys) {
1707
1736
  if (!schemaClusteringKeys.has(key)) {
1708
- return true;
1737
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1709
1738
  }
1710
1739
  }
1711
1740
  } else if (clusteringKeyResult.rows.length > 0) {
1712
- return true;
1741
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1713
1742
  }
1714
- return false;
1743
+ return { hasChanges: false, reasons: [] };
1715
1744
  } catch (error) {
1716
1745
  console.error("\u68C0\u67E5\u4E3B\u952E\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1717
- return false;
1746
+ return { hasChanges: false, reasons: [] };
1718
1747
  }
1719
1748
  }
1720
1749
  // 检查字段类型变更
@@ -1730,14 +1759,17 @@ var Model = class _Model {
1730
1759
  );
1731
1760
  const existingType = existingField.type.toLowerCase();
1732
1761
  if (!this.isTypeCompatible(existingType, schemaType)) {
1733
- return true;
1762
+ return {
1763
+ hasChanges: true,
1764
+ reasons: [`\u5B57\u6BB5\u7C7B\u578B\u4E0D\u517C\u5BB9: ${field} (${existingType} \u2192 ${schemaType})`]
1765
+ };
1734
1766
  }
1735
1767
  }
1736
1768
  }
1737
- return false;
1769
+ return { hasChanges: false, reasons: [] };
1738
1770
  } catch (error) {
1739
1771
  console.error("\u68C0\u67E5\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1740
- return false;
1772
+ return { hasChanges: false, reasons: [] };
1741
1773
  }
1742
1774
  }
1743
1775
  // 获取 Cassandra 类型
package/dist/mod.js CHANGED
@@ -1525,10 +1525,12 @@ var Model = class _Model {
1525
1525
  // 同步 Schema
1526
1526
  async syncSchema(force = false) {
1527
1527
  try {
1528
+ console.log(`\u{1F504} \u5F00\u59CB\u540C\u6B65\u8868: ${this.schema.keyspace}.${this.schema.tableName}`);
1528
1529
  const operations = await this.syncTableSchema(force);
1530
+ console.log(`\u2705 \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5B8C\u6210`);
1529
1531
  return operations.join("\n");
1530
1532
  } catch (error) {
1531
- console.error("\u540C\u6B65\u8868\u7ED3\u6784\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1533
+ console.error(`\u274C \u8868 ${this.schema.keyspace}.${this.schema.tableName} \u540C\u6B65\u5931\u8D25:`, error);
1532
1534
  throw error;
1533
1535
  }
1534
1536
  }
@@ -1536,6 +1538,12 @@ var Model = class _Model {
1536
1538
  async syncTableSchema(forceRecreate = false) {
1537
1539
  const operations = [];
1538
1540
  try {
1541
+ console.log(` \u{1F4CB} \u8868\u7ED3\u6784: ${this.schema.keyspace}.${this.schema.tableName}`);
1542
+ console.log(` \u{1F511} \u5206\u533A\u952E: [${this.schema.partitionKey.join(", ")}]`);
1543
+ if (this.schema.clusteringKey) {
1544
+ console.log(` \u{1F4CA} \u805A\u7C7B\u952E: ${Object.entries(this.schema.clusteringKey).map(([k, v]) => `${k}:${v}`).join(", ")}`);
1545
+ }
1546
+ console.log(` \u{1F4DD} \u5B57\u6BB5\u6570\u91CF: ${Object.keys(this.schema.fields.shape).length}`);
1539
1547
  await this.client.execute(
1540
1548
  queryHelper.ensureKeyspace(
1541
1549
  this.schema.keyspace,
@@ -1549,10 +1557,11 @@ var Model = class _Model {
1549
1557
  operations.push(...indexQueries);
1550
1558
  } else {
1551
1559
  const tableChanges = await this.analyzeTableChanges();
1552
- const hasUnalterableChanges = tableChanges.some(
1553
- (op) => op.startsWith("DROP TABLE")
1554
- );
1560
+ const hasUnalterableChanges = tableChanges.unalterableReasons.length > 0;
1555
1561
  if (forceRecreate && hasUnalterableChanges) {
1562
+ console.log("\u68C0\u6D4B\u5230\u4E0D\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u91CD\u5EFA\u8868");
1563
+ console.log("\u4E0D\u53EF\u53D8\u66F4\u539F\u56E0:", tableChanges.unalterableReasons);
1564
+ console.log("\u6240\u6709\u53D8\u66F4:", tableChanges.changes);
1556
1565
  operations.push(
1557
1566
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1558
1567
  );
@@ -1560,15 +1569,23 @@ var Model = class _Model {
1560
1569
  const indexQueries = queryHelper.createIndexes(this.schema);
1561
1570
  operations.push(...indexQueries);
1562
1571
  } else if (forceRecreate && !hasUnalterableChanges) {
1563
- operations.push(...tableChanges);
1572
+ console.log("\u68C0\u6D4B\u5230\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u4F7F\u7528 ALTER TABLE");
1573
+ console.log("\u53D8\u66F4\u8BE6\u60C5:", tableChanges.changes);
1574
+ operations.push(...tableChanges.operations);
1564
1575
  const indexOperations = await this.syncIndexes();
1565
1576
  operations.push(...indexOperations);
1566
1577
  } else if (!forceRecreate && hasUnalterableChanges) {
1578
+ const reasons = tableChanges.unalterableReasons.join("; ");
1567
1579
  throw new Error(
1568
- `\u8868\u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A\u4E3B\u952E\u53D8\u66F4\u3001\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\u7B49\u3002`
1580
+ `\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u5B58\u5728\u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\uFF0C\u9700\u8981\u4F7F\u7528 forceRecreate=true \u6765\u91CD\u5EFA\u8868\u3002
1581
+ \u4E0D\u53EF\u53D8\u66F4\u7684\u4FEE\u6539\u5305\u62EC\uFF1A
1582
+ ${reasons}
1583
+ \u5176\u4ED6\u53D8\u66F4\uFF1A${tableChanges.changes.join("; ")}`
1569
1584
  );
1570
1585
  } else {
1571
- operations.push(...tableChanges);
1586
+ console.log("\u68C0\u6D4B\u5230\u53EF\u53D8\u66F4\u7684\u8868\u7ED3\u6784\u4FEE\u6539\uFF0C\u5C06\u4F7F\u7528 ALTER TABLE");
1587
+ console.log("\u53D8\u66F4\u8BE6\u60C5:", tableChanges.changes);
1588
+ operations.push(...tableChanges.operations);
1572
1589
  const indexOperations = await this.syncIndexes();
1573
1590
  operations.push(...indexOperations);
1574
1591
  }
@@ -1597,6 +1614,8 @@ var Model = class _Model {
1597
1614
  // 分析表结构变更
1598
1615
  async analyzeTableChanges() {
1599
1616
  const operations = [];
1617
+ const changes = [];
1618
+ const unalterableReasons = [];
1600
1619
  try {
1601
1620
  const tableMetadata2 = await this.client.execute(queryHelper.tableMetadata(), [
1602
1621
  this.schema.keyspace,
@@ -1605,34 +1624,44 @@ var Model = class _Model {
1605
1624
  const schemaFields = Object.keys(this.schema.fields.shape);
1606
1625
  const newFields = this.getNewFields(schemaFields, tableMetadata2);
1607
1626
  const deletedFields = this.getDeletedFields(schemaFields, tableMetadata2);
1608
- const hasPrimaryKeyChanges = await this.checkPrimaryKeyChanges();
1609
- if (hasPrimaryKeyChanges) {
1627
+ if (newFields.length > 0) {
1628
+ changes.push(`\u65B0\u589E\u5B57\u6BB5: ${newFields.join(", ")}`);
1629
+ operations.push(queryHelper.addColumns(this.schema, newFields));
1630
+ }
1631
+ if (deletedFields.length > 0) {
1632
+ changes.push(`\u5220\u9664\u5B57\u6BB5: ${deletedFields.join(", ")}`);
1633
+ operations.push(queryHelper.dropColumns(this.schema, deletedFields));
1634
+ }
1635
+ const primaryKeyChanges = await this.checkPrimaryKeyChanges();
1636
+ if (primaryKeyChanges.hasChanges) {
1637
+ unalterableReasons.push(
1638
+ `\u4E3B\u952E\u53D8\u66F4: ${primaryKeyChanges.reasons.join(", ")}`
1639
+ );
1610
1640
  operations.push(
1611
1641
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1612
1642
  );
1613
1643
  operations.push(queryHelper.createTable(this.schema));
1614
- return operations;
1644
+ const indexQueries = queryHelper.createIndexes(this.schema);
1645
+ operations.push(...indexQueries);
1615
1646
  }
1616
- const hasTypeChanges = await this.checkFieldTypeChanges(tableMetadata2);
1617
- if (hasTypeChanges) {
1647
+ const typeChanges = await this.checkFieldTypeChanges(tableMetadata2);
1648
+ if (typeChanges.hasChanges) {
1649
+ unalterableReasons.push(
1650
+ `\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${typeChanges.reasons.join(", ")}`
1651
+ );
1618
1652
  operations.push(
1619
1653
  queryHelper.dropTable(this.schema.keyspace, this.schema.tableName)
1620
1654
  );
1621
1655
  operations.push(queryHelper.createTable(this.schema));
1622
- return operations;
1623
- }
1624
- if (newFields.length > 0) {
1625
- const addQuery = queryHelper.addColumns(this.schema, newFields);
1626
- operations.push(addQuery);
1627
- }
1628
- if (deletedFields.length > 0) {
1629
- const dropQuery = queryHelper.dropColumns(this.schema, deletedFields);
1630
- operations.push(dropQuery);
1656
+ const indexQueries = queryHelper.createIndexes(this.schema);
1657
+ operations.push(...indexQueries);
1631
1658
  }
1659
+ const indexOperations = await this.syncIndexes();
1660
+ operations.push(...indexOperations);
1661
+ return { operations, changes, unalterableReasons };
1632
1662
  } catch (error) {
1633
- console.error("\u5206\u6790\u8868\u7ED3\u6784\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1663
+ throw new Error(`\u5206\u6790\u8868 ${this.schema.keyspace}.${this.schema.tableName} \u7ED3\u6784\u53D8\u66F4\u5931\u8D25: ${error}`);
1634
1664
  }
1635
- return operations;
1636
1665
  }
1637
1666
  // 智能同步索引
1638
1667
  async syncIndexes() {
@@ -1673,7 +1702,7 @@ var Model = class _Model {
1673
1702
  [this.schema.keyspace, this.schema.tableName]
1674
1703
  );
1675
1704
  if (partitionKeyResult.rows.length !== this.schema.partitionKey.length) {
1676
- return true;
1705
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u6570\u91CF\u4E0D\u4E00\u81F4"] };
1677
1706
  }
1678
1707
  const existingPartitionKeys = new Set(
1679
1708
  partitionKeyResult.rows.map((row) => row.column_name.toLowerCase())
@@ -1682,11 +1711,11 @@ var Model = class _Model {
1682
1711
  this.schema.partitionKey.map((key) => String(key).toLowerCase())
1683
1712
  );
1684
1713
  if (existingPartitionKeys.size !== schemaPartitionKeys.size) {
1685
- return true;
1714
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u5B57\u6BB5\u540D\u4E0D\u4E00\u81F4"] };
1686
1715
  }
1687
1716
  for (const key of existingPartitionKeys) {
1688
1717
  if (!schemaPartitionKeys.has(key)) {
1689
- return true;
1718
+ return { hasChanges: true, reasons: ["\u5206\u533A\u952E\u5B57\u6BB5\u540D\u4E0D\u4E00\u81F4"] };
1690
1719
  }
1691
1720
  }
1692
1721
  if (this.schema.clusteringKey) {
@@ -1699,20 +1728,20 @@ var Model = class _Model {
1699
1728
  Object.keys(this.schema.clusteringKey).map((key) => key.toLowerCase())
1700
1729
  );
1701
1730
  if (existingClusteringKeys.size !== schemaClusteringKeys.size) {
1702
- return true;
1731
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1703
1732
  }
1704
1733
  for (const key of existingClusteringKeys) {
1705
1734
  if (!schemaClusteringKeys.has(key)) {
1706
- return true;
1735
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1707
1736
  }
1708
1737
  }
1709
1738
  } else if (clusteringKeyResult.rows.length > 0) {
1710
- return true;
1739
+ return { hasChanges: true, reasons: ["\u805A\u7C7B\u952E\u914D\u7F6E\u4E0D\u4E00\u81F4"] };
1711
1740
  }
1712
- return false;
1741
+ return { hasChanges: false, reasons: [] };
1713
1742
  } catch (error) {
1714
1743
  console.error("\u68C0\u67E5\u4E3B\u952E\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1715
- return false;
1744
+ return { hasChanges: false, reasons: [] };
1716
1745
  }
1717
1746
  }
1718
1747
  // 检查字段类型变更
@@ -1728,14 +1757,17 @@ var Model = class _Model {
1728
1757
  );
1729
1758
  const existingType = existingField.type.toLowerCase();
1730
1759
  if (!this.isTypeCompatible(existingType, schemaType)) {
1731
- return true;
1760
+ return {
1761
+ hasChanges: true,
1762
+ reasons: [`\u5B57\u6BB5\u7C7B\u578B\u4E0D\u517C\u5BB9: ${field} (${existingType} \u2192 ${schemaType})`]
1763
+ };
1732
1764
  }
1733
1765
  }
1734
1766
  }
1735
- return false;
1767
+ return { hasChanges: false, reasons: [] };
1736
1768
  } catch (error) {
1737
1769
  console.error("\u68C0\u67E5\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\u65F6\u53D1\u751F\u9519\u8BEF:", error);
1738
- return false;
1770
+ return { hasChanges: false, reasons: [] };
1739
1771
  }
1740
1772
  }
1741
1773
  // 获取 Cassandra 类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imean-cassandra-orm",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "cassandra orm",
5
5
  "keywords": [
6
6
  "cassandra",