Skip to content

Commit 9525e74

Browse files
committed
Replace the auto-locking of schemas by an explicit "lockSchemas" parameter
1 parent 14695f5 commit 9525e74

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

spec/DefinedSchemas.spec.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,26 +530,30 @@ describe('DefinedSchemas', () => {
530530
expect(schema.className).toEqual('Test');
531531
});
532532

533-
it('should disable class PUT/POST endpoint when schemas provided to avoid dual source of truth', async () => {
533+
it('should disable class PUT/POST endpoint when lockSchemas provided to avoid dual source of truth', async () => {
534534
await reconfigureServer({
535-
migrations: { schemas: [{ className: '_User' }, { className: 'Test' }] },
535+
migrations: {
536+
lockSchemas: true,
537+
schemas: [{ className: '_User' }, { className: 'Test' }],
538+
},
536539
});
537-
await reconfigureServer({ migrations: { schemas: [{ className: '_User' }] } });
538540

539541
const schema = await new Parse.Schema('Test').get();
540542
expect(schema.className).toEqual('Test');
541543

542544
const schemas = await Parse.Schema.all();
543-
expect(schemas.length).toEqual(4);
545+
expect(schemas.length).toEqual(3);
544546

545547
try {
546-
await new Parse.Schema('Test').save();
548+
await new Parse.Schema('TheNewTest').save();
549+
fail('TheNewTest.save() should have failed');
547550
} catch (e) {
548551
expect(e.message).toContain('Cannot perform this operation when schemas options is used.');
549552
}
550553

551554
try {
552555
await new Parse.Schema('_User').update();
556+
fail('_User.update() should have failed');
553557
} catch (e) {
554558
expect(e.message).toContain('Cannot perform this operation when schemas options is used.');
555559
}

src/Routers/SchemasRouter.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ function getOneSchema(req) {
3636
}
3737

3838
const checkIfDefinedSchemasIsUsed = req => {
39-
if (
40-
req.config &&
41-
req.config.migrations &&
42-
req.config.migrations.schemas &&
43-
req.config.migrations.schemas.length
44-
) {
39+
if (req.config && req.config.migrations && req.config.migrations.lockSchemas === true) {
4540
throw new Parse.Error(
4641
Parse.Error.OPERATION_FORBIDDEN,
4742
'Cannot perform this operation when schemas options is used.'

src/SchemaMigrations/Migrations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface MigrationsOptions {
3939
strict: ?boolean;
4040
deleteExtraFields: ?boolean;
4141
recreateModifiedFields: ?boolean;
42+
lockSchemas: ?boolean;
4243
/* Callback when server has started and before running schemas migration operations if schemas key provided */
4344
beforeSchemasMigration: ?() => void | Promise<void>;
4445
}

0 commit comments

Comments
 (0)