@strapi/database 5.0.0-beta.10 → 5.0.0-beta.12
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/entity-manager/regular-relations.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -10
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/internal.d.ts.map +1 -1
- package/dist/migrations/logger.d.ts +10 -0
- package/dist/migrations/logger.d.ts.map +1 -0
- package/dist/migrations/users.d.ts.map +1 -1
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -4735,7 +4735,7 @@ const deleteRelatedMorphOneRelationsAfterMorphToManyUpdate = async (rows, {
|
|
|
4735
4735
|
await createQueryBuilder(joinTable.name, db).delete().where({ $or: orWhere }).transacting(trx).execute();
|
|
4736
4736
|
}
|
|
4737
4737
|
};
|
|
4738
|
-
const getDocumentSiblingIdsQuery = (
|
|
4738
|
+
const getDocumentSiblingIdsQuery = (tableName, id) => {
|
|
4739
4739
|
const models = Array.from(strapi.db.metadata.values());
|
|
4740
4740
|
const isContentType = models.find((model) => {
|
|
4741
4741
|
return model.tableName === tableName && model.attributes.documentId;
|
|
@@ -4743,10 +4743,12 @@ const getDocumentSiblingIdsQuery = (con, tableName, id) => {
|
|
|
4743
4743
|
if (!isContentType) {
|
|
4744
4744
|
return [id];
|
|
4745
4745
|
}
|
|
4746
|
-
return con
|
|
4747
|
-
"
|
|
4748
|
-
|
|
4749
|
-
|
|
4746
|
+
return (con) => {
|
|
4747
|
+
con.from(tableName).select("id").where(
|
|
4748
|
+
"document_id",
|
|
4749
|
+
(con2) => con2.select("document_id").from(tableName).where("id", id)
|
|
4750
|
+
);
|
|
4751
|
+
};
|
|
4750
4752
|
};
|
|
4751
4753
|
const deletePreviousOneToAnyRelations = async ({
|
|
4752
4754
|
id,
|
|
@@ -4763,7 +4765,11 @@ const deletePreviousOneToAnyRelations = async ({
|
|
|
4763
4765
|
const { joinTable } = attribute;
|
|
4764
4766
|
const { joinColumn, inverseJoinColumn } = joinTable;
|
|
4765
4767
|
const con = db.getConnection();
|
|
4766
|
-
await con.delete().from(joinTable.name).whereNotIn(
|
|
4768
|
+
await con.delete().from(joinTable.name).whereNotIn(
|
|
4769
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4770
|
+
joinColumn.name,
|
|
4771
|
+
getDocumentSiblingIdsQuery(joinColumn.referencedTable, id)
|
|
4772
|
+
).whereIn(inverseJoinColumn.name, relIdsToadd).where(joinTable.on || {}).transacting(trx);
|
|
4767
4773
|
await cleanOrderColumns({ attribute, db, inverseRelIds: relIdsToadd, transaction: trx });
|
|
4768
4774
|
};
|
|
4769
4775
|
const deletePreviousAnyToOneRelations = async ({
|
|
@@ -4781,8 +4787,9 @@ const deletePreviousAnyToOneRelations = async ({
|
|
|
4781
4787
|
}
|
|
4782
4788
|
if (isManyToAny(attribute)) {
|
|
4783
4789
|
const relsToDelete = await con.select(inverseJoinColumn.name).from(joinTable.name).where(joinColumn.name, id).whereNotIn(
|
|
4790
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4784
4791
|
inverseJoinColumn.name,
|
|
4785
|
-
getDocumentSiblingIdsQuery(
|
|
4792
|
+
getDocumentSiblingIdsQuery(inverseJoinColumn.referencedTable, relIdToadd)
|
|
4786
4793
|
).where(joinTable.on || {}).transacting(trx);
|
|
4787
4794
|
const relIdsToDelete = map(inverseJoinColumn.name, relsToDelete);
|
|
4788
4795
|
await createQueryBuilder(joinTable.name, db).delete().where({
|
|
@@ -4792,8 +4799,9 @@ const deletePreviousAnyToOneRelations = async ({
|
|
|
4792
4799
|
await cleanOrderColumns({ attribute, db, inverseRelIds: relIdsToDelete, transaction: trx });
|
|
4793
4800
|
} else {
|
|
4794
4801
|
await con.delete().from(joinTable.name).where(joinColumn.name, id).whereNotIn(
|
|
4802
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4795
4803
|
inverseJoinColumn.name,
|
|
4796
|
-
getDocumentSiblingIdsQuery(
|
|
4804
|
+
getDocumentSiblingIdsQuery(inverseJoinColumn.referencedTable, relIdToadd)
|
|
4797
4805
|
).where(joinTable.on || {}).transacting(trx);
|
|
4798
4806
|
}
|
|
4799
4807
|
};
|
|
@@ -5877,6 +5885,21 @@ const createStorage = (opts) => {
|
|
|
5877
5885
|
const wrapTransaction = (db) => (fn) => () => {
|
|
5878
5886
|
return db.transaction(({ trx }) => Promise.resolve(fn(trx, db)));
|
|
5879
5887
|
};
|
|
5888
|
+
const transformLogMessage = (level, message) => {
|
|
5889
|
+
if (typeof message === "string") {
|
|
5890
|
+
return { level, message };
|
|
5891
|
+
}
|
|
5892
|
+
if (typeof message === "object" && message !== null) {
|
|
5893
|
+
if ("event" in message && "name" in message) {
|
|
5894
|
+
return {
|
|
5895
|
+
level,
|
|
5896
|
+
message: `[internal migration]: ${message.event} ${message?.name}`,
|
|
5897
|
+
timestamp: Date.now()
|
|
5898
|
+
};
|
|
5899
|
+
}
|
|
5900
|
+
}
|
|
5901
|
+
return "";
|
|
5902
|
+
};
|
|
5880
5903
|
const migrationResolver = ({ name, path: path2, context }) => {
|
|
5881
5904
|
const { db } = context;
|
|
5882
5905
|
if (!path2) {
|
|
@@ -5905,7 +5928,20 @@ const createUserMigrationProvider = (db) => {
|
|
|
5905
5928
|
const context = { db };
|
|
5906
5929
|
const umzugProvider = new Umzug({
|
|
5907
5930
|
storage: createStorage({ db, tableName: "strapi_migrations" }),
|
|
5908
|
-
logger:
|
|
5931
|
+
logger: {
|
|
5932
|
+
info(message) {
|
|
5933
|
+
db.logger.info(transformLogMessage("info", message));
|
|
5934
|
+
},
|
|
5935
|
+
warn(message) {
|
|
5936
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
5937
|
+
},
|
|
5938
|
+
error(message) {
|
|
5939
|
+
db.logger.error(transformLogMessage("error", message));
|
|
5940
|
+
},
|
|
5941
|
+
debug(message) {
|
|
5942
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
5943
|
+
}
|
|
5944
|
+
},
|
|
5909
5945
|
context,
|
|
5910
5946
|
migrations: {
|
|
5911
5947
|
glob: ["*.{js,sql}", { cwd: dir }],
|
|
@@ -6230,7 +6266,20 @@ const createInternalMigrationProvider = (db) => {
|
|
|
6230
6266
|
const migrations = [...internalMigrations];
|
|
6231
6267
|
const umzugProvider = new Umzug({
|
|
6232
6268
|
storage: createStorage({ db, tableName: "strapi_migrations_internal" }),
|
|
6233
|
-
logger:
|
|
6269
|
+
logger: {
|
|
6270
|
+
info(message) {
|
|
6271
|
+
db.logger.debug(transformLogMessage("info", message));
|
|
6272
|
+
},
|
|
6273
|
+
warn(message) {
|
|
6274
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
6275
|
+
},
|
|
6276
|
+
error(message) {
|
|
6277
|
+
db.logger.error(transformLogMessage("error", message));
|
|
6278
|
+
},
|
|
6279
|
+
debug(message) {
|
|
6280
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
6281
|
+
}
|
|
6282
|
+
},
|
|
6234
6283
|
context,
|
|
6235
6284
|
migrations: () => migrations.map((migration) => {
|
|
6236
6285
|
return {
|
|
@@ -6501,6 +6550,7 @@ class Database {
|
|
|
6501
6550
|
migrations;
|
|
6502
6551
|
lifecycles;
|
|
6503
6552
|
entityManager;
|
|
6553
|
+
logger;
|
|
6504
6554
|
constructor(config) {
|
|
6505
6555
|
this.config = {
|
|
6506
6556
|
...config,
|
|
@@ -6520,6 +6570,7 @@ class Database {
|
|
|
6520
6570
|
this.migrations = createMigrationsProvider(this);
|
|
6521
6571
|
this.lifecycles = createLifecyclesProvider(this);
|
|
6522
6572
|
this.entityManager = createEntityManager(this);
|
|
6573
|
+
this.logger = config.logger ?? console;
|
|
6523
6574
|
}
|
|
6524
6575
|
async init({ models }) {
|
|
6525
6576
|
this.metadata.loadModels(models);
|