Skip to content

Move 'ns not found' into mongo adapter. #1541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ export class MongoStorageAdapter {
});
}

dropCollection(name: string) {
return this.collection(this._collectionPrefix + name).then(collection => collection.drop());
dropCollection(className: string) {
return this.collection(this._collectionPrefix + className).then(collection => collection.drop())
.catch(error => {
// 'ns not found' means collection was already gone. Ignore deletion attempt.
if (error.message == 'ns not found') {
return Promise.resolve();
}
return Promise.reject(error);
});
}

// Used for testing only right now.
Expand Down
4 changes: 0 additions & 4 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ DatabaseController.prototype.collectionExists = function(className) {
return this.adapter.collectionExists(className);
};

DatabaseController.prototype.dropCollection = function(className) {
return this.adapter.dropCollection(className);
};

DatabaseController.prototype.validateClassName = function(className) {
if (this.skipValidation) {
return Promise.resolve();
Expand Down
14 changes: 2 additions & 12 deletions src/Routers/SchemasRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var removeJoinTables = (database, mongoSchema) => {
.filter(field => mongoSchema[field].startsWith('relation<'))
.map(field => {
let collectionName = `_Join:${field}:${mongoSchema._id}`;
return database.dropCollection(collectionName);
return database.adapter.dropCollection(collectionName);
})
);
};
Expand All @@ -117,17 +117,7 @@ function deleteSchema(req) {
return removeJoinTables(req.config.database, document);
});
})
.then(() => {
// Success
return { response: {} };
}, error => {
if (error.message == 'ns not found') {
// If they try to delete a non-existent class, that's fine, just let them.
return { response: {} };
}

return Promise.reject(error);
});
.then(() => ({ response: {} }));
}

export class SchemasRouter extends PromiseRouter {
Expand Down
10 changes: 1 addition & 9 deletions src/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,7 @@ class Schema {
if (this.data[className][fieldName].type == 'Relation') {
//For relations, drop the _Join table
return database.adapter.deleteFields(className, [fieldName], [])
.then(() => database.dropCollection(`_Join:${fieldName}:${className}`))
.catch(error => {
// 'ns not found' means collection was already gone. Ignore deletion attempt.
// TODO: 'ns not found' is a mongo implementation detail. Move it into mongo adapter.
if (error.message == 'ns not found') {
return Promise.resolve();
}
return Promise.reject(error);
});
.then(() => database.adapter.dropCollection(`_Join:${fieldName}:${className}`));
}

const fieldNames = [fieldName];
Expand Down