Skip to content

Commit 0822904

Browse files
committed
Fix logging, fix CLP not handled correctly for new schemas, ensure we exit on error
1 parent 85f6a02 commit 0822904

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/SchemaMigrations/DefinedSchemas.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class DefinedSchemas {
2121
this.migrationsOptions = migrationsOptions;
2222

2323
if (migrationsOptions && migrationsOptions.schemas) {
24+
if (!Array.isArray(migrationsOptions.schemas)) {
25+
throw `"migrations.schemas" must be an array of schemas`;
26+
}
27+
2428
this.localSchemas = migrationsOptions.schemas;
2529
}
2630

@@ -63,6 +67,7 @@ export class DefinedSchemas {
6367
async execute() {
6468
let timeout = null;
6569
try {
70+
logger.info('Running Migrations');
6671
// Set up a time out in production
6772
// if we fail to get schema
6873
// pm2 or K8s and many other process managers will try to restart the process
@@ -82,9 +87,11 @@ export class DefinedSchemas {
8287

8388
this.checkForMissingSchemas();
8489
await this.enforceCLPForNonProvidedClass();
90+
91+
logger.info('Running Migrations Completed');
8592
} catch (e) {
8693
if (timeout) clearTimeout(timeout);
87-
if (this.retries < this.maxRetries) {
94+
if (!e && this.retries < this.maxRetries) {
8895
this.retries++;
8996
// first retry 1sec, 2sec, 3sec total 6sec retry sequence
9097
// retry will only happen in case of deploying multi parse server instance
@@ -93,8 +100,11 @@ export class DefinedSchemas {
93100
await this.wait(1000 * this.retries);
94101
await this.execute();
95102
} else {
96-
logger.error(e);
97-
if (process.env.NODE_ENV === 'production') process.exit(1);
103+
if (e) {
104+
logger.error(`Failed to run migrations ${e}`);
105+
}
106+
107+
if (this.migrationsOptions.strict) process.exit(1);
98108
}
99109
}
100110
}
@@ -159,7 +169,7 @@ export class DefinedSchemas {
159169
try {
160170
await this.saveSchema(localSchema);
161171
} catch (e) {
162-
logger.error(`Error while saving Schema for type ${cloudSchema.className}: ${e}`);
172+
logger.error(`Error while saving Schema for type ${localSchema.className}: ${e}`);
163173
throw e;
164174
}
165175
}
@@ -340,14 +350,14 @@ export class DefinedSchemas {
340350
}
341351
// Use spread to avoid read only issue (encountered by Moumouls using directAccess)
342352
const clp = { ...localSchema.classLevelPermissions } || {};
343-
const cloudCLP = (cloudSchema && cloudSchema.classLevelPermissions) || {};
344-
// Try to inject default CLPs
345-
const CLPKeys = ['find', 'count', 'get', 'create', 'update', 'delete', 'addField'];
346-
CLPKeys.forEach(key => {
347-
if (!clp[key]) {
348-
clp[key] = cloudCLP[key] || { '*': false };
349-
}
350-
});
353+
// const cloudCLP = (cloudSchema && cloudSchema.classLevelPermissions) || {};
354+
// // Try to inject default CLPs
355+
// const CLPKeys = ['find', 'count', 'get', 'create', 'update', 'delete', 'addField'];
356+
// CLPKeys.forEach(key => {
357+
// if (!clp[key] && cloudCLP[key]) {
358+
// clp[key] = cloudCLP[key];
359+
// }
360+
// });
351361
// To avoid inconsistency we need to remove all rights on addField
352362
clp.addField = {};
353363
newLocalSchema.setCLP(clp);

0 commit comments

Comments
 (0)