@strapi/database 4.25.23 → 4.26.0

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.mjs CHANGED
@@ -1330,7 +1330,7 @@ const createSchemaDiff = (db) => {
1330
1330
  const diffColumns = (oldColumn, column) => {
1331
1331
  const changes = [];
1332
1332
  const isIgnoredType = ["increments"].includes(column.type);
1333
- const oldType = oldColumn.type;
1333
+ const oldType = db.dialect.getSqlType(oldColumn.type);
1334
1334
  const type = db.dialect.getSqlType(column.type);
1335
1335
  if (oldType !== type && !isIgnoredType) {
1336
1336
  changes.push("type");
@@ -1573,7 +1573,7 @@ const createSchemaStorage = (db) => {
1573
1573
  };
1574
1574
  },
1575
1575
  hashSchema(schema) {
1576
- return crypto.createHash("md5").update(JSON.stringify(schema)).digest("hex");
1576
+ return crypto.createHash("sha256").update(JSON.stringify(schema)).digest("hex");
1577
1577
  },
1578
1578
  async add(schema) {
1579
1579
  await checkTableExists();
@@ -1821,10 +1821,10 @@ const createSchemaProvider = (db) => {
1821
1821
  await this.drop();
1822
1822
  await this.create();
1823
1823
  },
1824
- async syncSchema() {
1824
+ async syncSchema(oldSchema) {
1825
1825
  debug$1("Synchronizing database schema");
1826
- const DBSchema = await db.dialect.schemaInspector.getSchema();
1827
- const { status, diff } = await this.schemaDiff.diff(DBSchema, schema);
1826
+ const currentSchema = oldSchema ?? await db.dialect.schemaInspector.getSchema();
1827
+ const { status, diff } = await this.schemaDiff.diff(currentSchema, schema);
1828
1828
  if (status === "CHANGED") {
1829
1829
  await this.builder.updateSchema(diff);
1830
1830
  }
@@ -1849,6 +1849,10 @@ const createSchemaProvider = (db) => {
1849
1849
  const hash = await this.schemaStorage.hashSchema(schema);
1850
1850
  if (oldHash !== hash) {
1851
1851
  debug$1("Schema changed");
1852
+ if (!db.config.settings.strictSyncSchema) {
1853
+ debug$1("Syncing schema keeping not Strapi managed elements");
1854
+ return this.syncSchema(oldSchema.schema);
1855
+ }
1852
1856
  return this.syncSchema();
1853
1857
  }
1854
1858
  debug$1("Schema unchanged");
@@ -6228,6 +6232,7 @@ class Database {
6228
6232
  settings: {
6229
6233
  forceMigration: true,
6230
6234
  runMigrations: true,
6235
+ strictSyncSchema: true,
6231
6236
  ...config.settings ?? {}
6232
6237
  }
6233
6238
  };