Cleanup delete schema (#1604)

* Some cleanup for deleting one schema

* tidyness

* Remove _allCollections as Parse Server doesn't need it.
This commit is contained in:
Drew
2016-04-25 11:47:57 -07:00
committed by Florent Vilmart
parent d14d451028
commit 234d0093ff
4 changed files with 52 additions and 51 deletions

View File

@@ -70,7 +70,7 @@ var removeJoinTables = (database, mongoSchema) => {
.filter(field => mongoSchema[field].startsWith('relation<'))
.map(field => {
let collectionName = `_Join:${field}:${mongoSchema._id}`;
return database.adapter.dropCollection(collectionName);
return database.adapter.deleteOneSchema(collectionName);
})
);
};
@@ -79,22 +79,19 @@ function deleteSchema(req) {
if (!SchemaController.classNameIsValid(req.params.className)) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, SchemaController.invalidClassNameMessage(req.params.className));
}
return req.config.database.deleteSchema(req.params.className)
.then(() => {
// We've dropped the collection now, so delete the item from _SCHEMA
// and clear the _Join collections
return req.config.database.schemaCollection()
.then(coll => coll.findAndDeleteSchema(req.params.className))
.then(document => {
if (document === null) {
//tried to delete non-existent class
return Promise.resolve();
}
return removeJoinTables(req.config.database, document);
});
})
.then(() => ({ response: {} }));
.then(() => req.config.database.schemaCollection())
// We've dropped the collection now, so delete the item from _SCHEMA
// and clear the _Join collections
.then(coll => coll.findAndDeleteSchema(req.params.className))
.then(document => {
if (document === null) {
//tried to delete non-existent class
return Promise.resolve();
}
return removeJoinTables(req.config.database, document);
})
.then(() => ({ response: {} }));
}
export class SchemasRouter extends PromiseRouter {