Skip to content

Commit cecb2a1

Browse files
committed
Move 'ns not found' into mongo adapter. (#1541)
1 parent ab0ea09 commit cecb2a1

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ export class MongoStorageAdapter {
7070
});
7171
}
7272

73-
dropCollection(name: string) {
74-
return this.collection(this._collectionPrefix + name).then(collection => collection.drop());
73+
dropCollection(className: string) {
74+
return this.collection(this._collectionPrefix + className).then(collection => collection.drop())
75+
.catch(error => {
76+
// 'ns not found' means collection was already gone. Ignore deletion attempt.
77+
if (error.message == 'ns not found') {
78+
return Promise.resolve();
79+
}
80+
return Promise.reject(error);
81+
});
7582
}
7683

7784
// Used for testing only right now.

src/Controllers/DatabaseController.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ DatabaseController.prototype.collectionExists = function(className) {
4444
return this.adapter.collectionExists(className);
4545
};
4646

47-
DatabaseController.prototype.dropCollection = function(className) {
48-
return this.adapter.dropCollection(className);
49-
};
50-
5147
DatabaseController.prototype.validateClassName = function(className) {
5248
if (this.skipValidation) {
5349
return Promise.resolve();

src/Routers/SchemasRouter.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var removeJoinTables = (database, mongoSchema) => {
7070
.filter(field => mongoSchema[field].startsWith('relation<'))
7171
.map(field => {
7272
let collectionName = `_Join:${field}:${mongoSchema._id}`;
73-
return database.dropCollection(collectionName);
73+
return database.adapter.dropCollection(collectionName);
7474
})
7575
);
7676
};
@@ -94,17 +94,7 @@ function deleteSchema(req) {
9494
return removeJoinTables(req.config.database, document);
9595
});
9696
})
97-
.then(() => {
98-
// Success
99-
return { response: {} };
100-
}, error => {
101-
if (error.message == 'ns not found') {
102-
// If they try to delete a non-existent class, that's fine, just let them.
103-
return { response: {} };
104-
}
105-
106-
return Promise.reject(error);
107-
});
97+
.then(() => ({ response: {} }));
10898
}
10999

110100
export class SchemasRouter extends PromiseRouter {

src/Schema.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,7 @@ class SchemaController {
541541
if (this.data[className][fieldName].type == 'Relation') {
542542
//For relations, drop the _Join table
543543
return database.adapter.deleteFields(className, [fieldName], [])
544-
.then(() => database.dropCollection(`_Join:${fieldName}:${className}`))
545-
.catch(error => {
546-
// 'ns not found' means collection was already gone. Ignore deletion attempt.
547-
// TODO: 'ns not found' is a mongo implementation detail. Move it into mongo adapter.
548-
if (error.message == 'ns not found') {
549-
return Promise.resolve();
550-
}
551-
return Promise.reject(error);
552-
});
544+
.then(() => database.adapter.dropCollection(`_Join:${fieldName}:${className}`));
553545
}
554546

555547
const fieldNames = [fieldName];

0 commit comments

Comments
 (0)