@strapi/database 5.5.1 → 5.6.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/dialects/dialect.d.ts +2 -0
- package/dist/dialects/dialect.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -0
- package/dist/index.mjs.map +1 -1
- package/dist/repairs/index.d.ts +6 -0
- package/dist/repairs/index.d.ts.map +1 -0
- package/dist/repairs/operations/remove-orphan-morph-types.d.ts +18 -0
- package/dist/repairs/operations/remove-orphan-morph-types.d.ts.map +1 -0
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/utils/async-curry.d.ts +9 -0
- package/dist/utils/async-curry.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,9 @@ class Dialect {
|
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
31
|
async initialize(_nativeConnection) {
|
|
32
32
|
}
|
|
33
|
+
getTables() {
|
|
34
|
+
throw new Error("getTables not implemented for this dialect");
|
|
35
|
+
}
|
|
33
36
|
getSqlType(type) {
|
|
34
37
|
return type;
|
|
35
38
|
}
|
|
@@ -2206,6 +2209,7 @@ const createSchemaProvider = (db) => {
|
|
|
2206
2209
|
await this.builder.updateSchema(diff);
|
|
2207
2210
|
}
|
|
2208
2211
|
await this.schemaStorage.add(this.schema);
|
|
2212
|
+
return status;
|
|
2209
2213
|
},
|
|
2210
2214
|
// TODO: support options to migrate softly or forcefully
|
|
2211
2215
|
// TODO: support option to disable auto migration & run a CLI command instead to avoid doing it at startup
|
|
@@ -2228,6 +2232,7 @@ const createSchemaProvider = (db) => {
|
|
|
2228
2232
|
return this.syncSchema();
|
|
2229
2233
|
}
|
|
2230
2234
|
debug$1("Schema unchanged");
|
|
2235
|
+
return "UNCHANGED";
|
|
2231
2236
|
}
|
|
2232
2237
|
};
|
|
2233
2238
|
};
|
|
@@ -6903,6 +6908,64 @@ const validateRelations = async (db) => {
|
|
|
6903
6908
|
async function validateDatabase(db) {
|
|
6904
6909
|
await validateRelations(db);
|
|
6905
6910
|
}
|
|
6911
|
+
const isMorphRelationWithPivot = (attribute, pivot) => {
|
|
6912
|
+
return attribute.type === "relation" && "relation" in attribute && "joinTable" in attribute && "target" in attribute && "name" in attribute.joinTable && "pivotColumns" in attribute.joinTable && attribute.joinTable.pivotColumns.includes(pivot);
|
|
6913
|
+
};
|
|
6914
|
+
const filterMorphRelationalAttributes = (attributes, pivot) => {
|
|
6915
|
+
return Object.values(attributes).filter(
|
|
6916
|
+
(attribute) => isMorphRelationWithPivot(attribute, pivot)
|
|
6917
|
+
);
|
|
6918
|
+
};
|
|
6919
|
+
const removeOrphanMorphType = async (db, { pivot }) => {
|
|
6920
|
+
db.logger.debug(`Removing orphaned morph type: ${JSON.stringify(pivot)}`);
|
|
6921
|
+
const mdValues = db.metadata.values();
|
|
6922
|
+
for (const model of mdValues) {
|
|
6923
|
+
const attributes = filterMorphRelationalAttributes(model.attributes || {}, pivot);
|
|
6924
|
+
for (const attribute of attributes) {
|
|
6925
|
+
const joinTableName = attribute.joinTable.name;
|
|
6926
|
+
const morphTypes = await db.connection(joinTableName).distinct(pivot).pluck(pivot);
|
|
6927
|
+
for (const morphType of morphTypes) {
|
|
6928
|
+
const deleteComponentType = await (async () => {
|
|
6929
|
+
try {
|
|
6930
|
+
return !db.metadata.get(morphType);
|
|
6931
|
+
} catch {
|
|
6932
|
+
db.logger.debug(
|
|
6933
|
+
`Metadata for morph type "${morphType}" in table "${joinTableName}" not found`
|
|
6934
|
+
);
|
|
6935
|
+
return true;
|
|
6936
|
+
}
|
|
6937
|
+
})();
|
|
6938
|
+
if (deleteComponentType) {
|
|
6939
|
+
db.logger.debug(
|
|
6940
|
+
`Removing invalid morph type "${morphType}" from table "${joinTableName}".`
|
|
6941
|
+
);
|
|
6942
|
+
try {
|
|
6943
|
+
await db.connection(joinTableName).where(pivot, morphType).del();
|
|
6944
|
+
} catch (error) {
|
|
6945
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
6946
|
+
db.logger.error(
|
|
6947
|
+
`Failed to remove invalid morph type "${morphType}" from table "${joinTableName}": ${errorMessage}`
|
|
6948
|
+
);
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
}
|
|
6954
|
+
};
|
|
6955
|
+
const asyncCurry = (fn) => {
|
|
6956
|
+
const curried = (...args) => {
|
|
6957
|
+
if (args.length >= fn.length) {
|
|
6958
|
+
return fn(...args);
|
|
6959
|
+
}
|
|
6960
|
+
return (...moreArgs) => curried(...args, ...moreArgs);
|
|
6961
|
+
};
|
|
6962
|
+
return curried;
|
|
6963
|
+
};
|
|
6964
|
+
const createRepairManager = (db) => {
|
|
6965
|
+
return {
|
|
6966
|
+
removeOrphanMorphType: asyncCurry(removeOrphanMorphType)(db)
|
|
6967
|
+
};
|
|
6968
|
+
};
|
|
6906
6969
|
const afterCreate = (db) => (nativeConnection, done) => {
|
|
6907
6970
|
db.dialect.initialize(nativeConnection).then(() => {
|
|
6908
6971
|
return done(null, nativeConnection);
|
|
@@ -6917,6 +6980,7 @@ class Database {
|
|
|
6917
6980
|
migrations;
|
|
6918
6981
|
lifecycles;
|
|
6919
6982
|
entityManager;
|
|
6983
|
+
repair;
|
|
6920
6984
|
logger;
|
|
6921
6985
|
constructor(config) {
|
|
6922
6986
|
this.config = {
|
|
@@ -6953,6 +7017,7 @@ class Database {
|
|
|
6953
7017
|
this.migrations = createMigrationsProvider(this);
|
|
6954
7018
|
this.lifecycles = createLifecyclesProvider(this);
|
|
6955
7019
|
this.entityManager = createEntityManager(this);
|
|
7020
|
+
this.repair = createRepairManager(this);
|
|
6956
7021
|
}
|
|
6957
7022
|
async init({ models }) {
|
|
6958
7023
|
if (typeof this.config.connection.connection === "function") {
|