Move 'ns not found' into mongo adapter. (#1541)
This commit is contained in:
@@ -70,8 +70,15 @@ export class MongoStorageAdapter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dropCollection(name: string) {
|
dropCollection(className: string) {
|
||||||
return this.collection(this._collectionPrefix + name).then(collection => collection.drop());
|
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.
|
// Used for testing only right now.
|
||||||
|
|||||||
@@ -44,10 +44,6 @@ DatabaseController.prototype.collectionExists = function(className) {
|
|||||||
return this.adapter.collectionExists(className);
|
return this.adapter.collectionExists(className);
|
||||||
};
|
};
|
||||||
|
|
||||||
DatabaseController.prototype.dropCollection = function(className) {
|
|
||||||
return this.adapter.dropCollection(className);
|
|
||||||
};
|
|
||||||
|
|
||||||
DatabaseController.prototype.validateClassName = function(className) {
|
DatabaseController.prototype.validateClassName = function(className) {
|
||||||
if (this.skipValidation) {
|
if (this.skipValidation) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ var removeJoinTables = (database, mongoSchema) => {
|
|||||||
.filter(field => mongoSchema[field].startsWith('relation<'))
|
.filter(field => mongoSchema[field].startsWith('relation<'))
|
||||||
.map(field => {
|
.map(field => {
|
||||||
let collectionName = `_Join:${field}:${mongoSchema._id}`;
|
let collectionName = `_Join:${field}:${mongoSchema._id}`;
|
||||||
return database.dropCollection(collectionName);
|
return database.adapter.dropCollection(collectionName);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -94,17 +94,7 @@ function deleteSchema(req) {
|
|||||||
return removeJoinTables(req.config.database, document);
|
return removeJoinTables(req.config.database, document);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => ({ response: {} }));
|
||||||
// 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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SchemasRouter extends PromiseRouter {
|
export class SchemasRouter extends PromiseRouter {
|
||||||
|
|||||||
@@ -541,15 +541,7 @@ class SchemaController {
|
|||||||
if (this.data[className][fieldName].type == 'Relation') {
|
if (this.data[className][fieldName].type == 'Relation') {
|
||||||
//For relations, drop the _Join table
|
//For relations, drop the _Join table
|
||||||
return database.adapter.deleteFields(className, [fieldName], [])
|
return database.adapter.deleteFields(className, [fieldName], [])
|
||||||
.then(() => database.dropCollection(`_Join:${fieldName}:${className}`))
|
.then(() => database.adapter.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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldNames = [fieldName];
|
const fieldNames = [fieldName];
|
||||||
|
|||||||
Reference in New Issue
Block a user