@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regular-relations.d.ts","sourceRoot":"","sources":["../../src/entity-manager/regular-relations.ts"],"names":[],"mappings":";;;;;AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAYjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAS,MAAM,UAAU,CAAC;AAEpD,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,IAAI,CAAC;QACb,UAAU,kBAAkB;YAC1B,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SAC3C;KACF;CACF;
|
|
1
|
+
{"version":3,"file":"regular-relations.d.ts","sourceRoot":"","sources":["../../src/entity-manager/regular-relations.ts"],"names":[],"mappings":";;;;;AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAYjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAS,MAAM,UAAU,CAAC;AAEpD,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,IAAI,CAAC;QACb,UAAU,kBAAkB;YAC1B,W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@ interface Settings {
|
|
|
19
19
|
};
|
|
20
20
|
[key: string]: unknown;
|
|
21
21
|
}
|
|
22
|
+
export type Logger = Record<'info' | 'warn' | 'error' | 'debug', (message: string | Record<string, unknown>) => void>;
|
|
22
23
|
export interface DatabaseConfig {
|
|
23
24
|
connection: Knex.Config;
|
|
24
25
|
settings: Settings;
|
|
26
|
+
logger?: Logger;
|
|
25
27
|
}
|
|
26
28
|
declare class Database {
|
|
27
29
|
connection: Knex;
|
|
@@ -32,6 +34,7 @@ declare class Database {
|
|
|
32
34
|
migrations: MigrationProvider;
|
|
33
35
|
lifecycles: LifecycleProvider;
|
|
34
36
|
entityManager: EntityManager;
|
|
37
|
+
logger: Logger;
|
|
35
38
|
constructor(config: DatabaseConfig);
|
|
36
39
|
init({ models }: {
|
|
37
40
|
models: Model[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACjD,OAAO,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAkB,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAuB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAA4B,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAA4B,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEpF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,W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AAY,CAAC,GAAG,EAAE,MAAM;IAIlB,OAAO;CAId;AAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5B,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4767,7 +4767,7 @@ const deleteRelatedMorphOneRelationsAfterMorphToManyUpdate = async (rows, {
|
|
|
4767
4767
|
await createQueryBuilder(joinTable.name, db).delete().where({ $or: orWhere }).transacting(trx).execute();
|
|
4768
4768
|
}
|
|
4769
4769
|
};
|
|
4770
|
-
const getDocumentSiblingIdsQuery = (
|
|
4770
|
+
const getDocumentSiblingIdsQuery = (tableName, id) => {
|
|
4771
4771
|
const models = Array.from(strapi.db.metadata.values());
|
|
4772
4772
|
const isContentType = models.find((model) => {
|
|
4773
4773
|
return model.tableName === tableName && model.attributes.documentId;
|
|
@@ -4775,10 +4775,12 @@ const getDocumentSiblingIdsQuery = (con, tableName, id) => {
|
|
|
4775
4775
|
if (!isContentType) {
|
|
4776
4776
|
return [id];
|
|
4777
4777
|
}
|
|
4778
|
-
return con
|
|
4779
|
-
"
|
|
4780
|
-
|
|
4781
|
-
|
|
4778
|
+
return (con) => {
|
|
4779
|
+
con.from(tableName).select("id").where(
|
|
4780
|
+
"document_id",
|
|
4781
|
+
(con2) => con2.select("document_id").from(tableName).where("id", id)
|
|
4782
|
+
);
|
|
4783
|
+
};
|
|
4782
4784
|
};
|
|
4783
4785
|
const deletePreviousOneToAnyRelations = async ({
|
|
4784
4786
|
id,
|
|
@@ -4795,7 +4797,11 @@ const deletePreviousOneToAnyRelations = async ({
|
|
|
4795
4797
|
const { joinTable } = attribute;
|
|
4796
4798
|
const { joinColumn, inverseJoinColumn } = joinTable;
|
|
4797
4799
|
const con = db.getConnection();
|
|
4798
|
-
await con.delete().from(joinTable.name).whereNotIn(
|
|
4800
|
+
await con.delete().from(joinTable.name).whereNotIn(
|
|
4801
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4802
|
+
joinColumn.name,
|
|
4803
|
+
getDocumentSiblingIdsQuery(joinColumn.referencedTable, id)
|
|
4804
|
+
).whereIn(inverseJoinColumn.name, relIdsToadd).where(joinTable.on || {}).transacting(trx);
|
|
4799
4805
|
await cleanOrderColumns({ attribute, db, inverseRelIds: relIdsToadd, transaction: trx });
|
|
4800
4806
|
};
|
|
4801
4807
|
const deletePreviousAnyToOneRelations = async ({
|
|
@@ -4813,8 +4819,9 @@ const deletePreviousAnyToOneRelations = async ({
|
|
|
4813
4819
|
}
|
|
4814
4820
|
if (isManyToAny(attribute)) {
|
|
4815
4821
|
const relsToDelete = await con.select(inverseJoinColumn.name).from(joinTable.name).where(joinColumn.name, id).whereNotIn(
|
|
4822
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4816
4823
|
inverseJoinColumn.name,
|
|
4817
|
-
getDocumentSiblingIdsQuery(
|
|
4824
|
+
getDocumentSiblingIdsQuery(inverseJoinColumn.referencedTable, relIdToadd)
|
|
4818
4825
|
).where(joinTable.on || {}).transacting(trx);
|
|
4819
4826
|
const relIdsToDelete = _.map(inverseJoinColumn.name, relsToDelete);
|
|
4820
4827
|
await createQueryBuilder(joinTable.name, db).delete().where({
|
|
@@ -4824,8 +4831,9 @@ const deletePreviousAnyToOneRelations = async ({
|
|
|
4824
4831
|
await cleanOrderColumns({ attribute, db, inverseRelIds: relIdsToDelete, transaction: trx });
|
|
4825
4832
|
} else {
|
|
4826
4833
|
await con.delete().from(joinTable.name).where(joinColumn.name, id).whereNotIn(
|
|
4834
|
+
// @ts-expect-error - knex incorrectly expects a string array
|
|
4827
4835
|
inverseJoinColumn.name,
|
|
4828
|
-
getDocumentSiblingIdsQuery(
|
|
4836
|
+
getDocumentSiblingIdsQuery(inverseJoinColumn.referencedTable, relIdToadd)
|
|
4829
4837
|
).where(joinTable.on || {}).transacting(trx);
|
|
4830
4838
|
}
|
|
4831
4839
|
};
|
|
@@ -5909,6 +5917,21 @@ const createStorage = (opts) => {
|
|
|
5909
5917
|
const wrapTransaction = (db) => (fn) => () => {
|
|
5910
5918
|
return db.transaction(({ trx }) => Promise.resolve(fn(trx, db)));
|
|
5911
5919
|
};
|
|
5920
|
+
const transformLogMessage = (level, message) => {
|
|
5921
|
+
if (typeof message === "string") {
|
|
5922
|
+
return { level, message };
|
|
5923
|
+
}
|
|
5924
|
+
if (typeof message === "object" && message !== null) {
|
|
5925
|
+
if ("event" in message && "name" in message) {
|
|
5926
|
+
return {
|
|
5927
|
+
level,
|
|
5928
|
+
message: `[internal migration]: ${message.event} ${message?.name}`,
|
|
5929
|
+
timestamp: Date.now()
|
|
5930
|
+
};
|
|
5931
|
+
}
|
|
5932
|
+
}
|
|
5933
|
+
return "";
|
|
5934
|
+
};
|
|
5912
5935
|
const migrationResolver = ({ name, path: path2, context }) => {
|
|
5913
5936
|
const { db } = context;
|
|
5914
5937
|
if (!path2) {
|
|
@@ -5937,7 +5960,20 @@ const createUserMigrationProvider = (db) => {
|
|
|
5937
5960
|
const context = { db };
|
|
5938
5961
|
const umzugProvider = new umzug.Umzug({
|
|
5939
5962
|
storage: createStorage({ db, tableName: "strapi_migrations" }),
|
|
5940
|
-
logger:
|
|
5963
|
+
logger: {
|
|
5964
|
+
info(message) {
|
|
5965
|
+
db.logger.info(transformLogMessage("info", message));
|
|
5966
|
+
},
|
|
5967
|
+
warn(message) {
|
|
5968
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
5969
|
+
},
|
|
5970
|
+
error(message) {
|
|
5971
|
+
db.logger.error(transformLogMessage("error", message));
|
|
5972
|
+
},
|
|
5973
|
+
debug(message) {
|
|
5974
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
5975
|
+
}
|
|
5976
|
+
},
|
|
5941
5977
|
context,
|
|
5942
5978
|
migrations: {
|
|
5943
5979
|
glob: ["*.{js,sql}", { cwd: dir }],
|
|
@@ -6262,7 +6298,20 @@ const createInternalMigrationProvider = (db) => {
|
|
|
6262
6298
|
const migrations = [...internalMigrations];
|
|
6263
6299
|
const umzugProvider = new umzug.Umzug({
|
|
6264
6300
|
storage: createStorage({ db, tableName: "strapi_migrations_internal" }),
|
|
6265
|
-
logger:
|
|
6301
|
+
logger: {
|
|
6302
|
+
info(message) {
|
|
6303
|
+
db.logger.debug(transformLogMessage("info", message));
|
|
6304
|
+
},
|
|
6305
|
+
warn(message) {
|
|
6306
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
6307
|
+
},
|
|
6308
|
+
error(message) {
|
|
6309
|
+
db.logger.error(transformLogMessage("error", message));
|
|
6310
|
+
},
|
|
6311
|
+
debug(message) {
|
|
6312
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
6313
|
+
}
|
|
6314
|
+
},
|
|
6266
6315
|
context,
|
|
6267
6316
|
migrations: () => migrations.map((migration) => {
|
|
6268
6317
|
return {
|
|
@@ -6533,6 +6582,7 @@ class Database {
|
|
|
6533
6582
|
migrations;
|
|
6534
6583
|
lifecycles;
|
|
6535
6584
|
entityManager;
|
|
6585
|
+
logger;
|
|
6536
6586
|
constructor(config) {
|
|
6537
6587
|
this.config = {
|
|
6538
6588
|
...config,
|
|
@@ -6552,6 +6602,7 @@ class Database {
|
|
|
6552
6602
|
this.migrations = createMigrationsProvider(this);
|
|
6553
6603
|
this.lifecycles = createLifecyclesProvider(this);
|
|
6554
6604
|
this.entityManager = createEntityManager(this);
|
|
6605
|
+
this.logger = config.logger ?? console;
|
|
6555
6606
|
}
|
|
6556
6607
|
async init({ models }) {
|
|
6557
6608
|
this.metadata.loadModels(models);
|