mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 08:38:09 +00:00
Fix mongoose destroy function & re-add strapi.stop calls
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
987a7c1022
commit
823070df9d
@ -47,12 +47,13 @@ const createConnectionURL = opts => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(strapi) {
|
module.exports = function(strapi) {
|
||||||
function initialize() {
|
|
||||||
const { connections } = strapi.config;
|
const { connections } = strapi.config;
|
||||||
|
const mongooseConnections = Object.keys(connections).filter(key =>
|
||||||
|
isMongooseConnection(connections[key])
|
||||||
|
);
|
||||||
|
|
||||||
const connectionsPromises = Object.keys(connections)
|
function initialize() {
|
||||||
.filter(key => isMongooseConnection(connections[key]))
|
const connectionsPromises = mongooseConnections.map(async connectionName => {
|
||||||
.map(async connectionName => {
|
|
||||||
const connection = connections[connectionName];
|
const connection = connections[connectionName];
|
||||||
const instance = new Mongoose();
|
const instance = new Mongoose();
|
||||||
|
|
||||||
@ -197,10 +198,21 @@ module.exports = function(strapi) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function destroy() {
|
||||||
|
for (const connName of mongooseConnections) {
|
||||||
|
const connection = strapi.connections[connName];
|
||||||
|
|
||||||
|
if (connection instanceof Mongoose) {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaults,
|
defaults,
|
||||||
initialize,
|
initialize,
|
||||||
getQueryParams,
|
getQueryParams,
|
||||||
|
destroy,
|
||||||
buildQuery,
|
buildQuery,
|
||||||
queries,
|
queries,
|
||||||
...relations,
|
...relations,
|
||||||
|
|||||||
@ -272,9 +272,9 @@ module.exports = async ({ models, target }, ctx) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only sync indexes in development env while it's not possible to create complex indexes directly from models
|
// Only sync indexes when not in production env while it's not possible to create complex indexes directly from models
|
||||||
// In other environments it will simply create missing indexes (those defined in the models but not present in db)
|
// In production it will simply create missing indexes (those defined in the models but not present in db)
|
||||||
if (strapi.app.env === 'development') {
|
if (strapi.app.env !== 'production') {
|
||||||
// Ensure indexes are synced with the model, prevent duplicate index errors
|
// Ensure indexes are synced with the model, prevent duplicate index errors
|
||||||
// Side-effect: Delete all the indexes not present in the model.json
|
// Side-effect: Delete all the indexes not present in the model.json
|
||||||
Model.syncIndexes(null, handleIndexesErrors);
|
Model.syncIndexes(null, handleIndexesErrors);
|
||||||
|
|||||||
@ -51,7 +51,7 @@ const createConnectorRegistry = ({ defaultConnection, connections }) => {
|
|||||||
|
|
||||||
getByConnection(connection) {
|
getByConnection(connection) {
|
||||||
if (!_.has(connections, connection)) {
|
if (!_.has(connections, connection)) {
|
||||||
throw new Error('Trying to access a connector for an unknow connection');
|
throw new Error('Trying to access a connector for an unknown connection');
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectorKey = connections[connection].connector;
|
const connectorKey = connections[connection].connector;
|
||||||
|
|||||||
@ -201,7 +201,9 @@ class Strapi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async destroy() {
|
async destroy() {
|
||||||
|
if (_.has(this, 'server.destroy')) {
|
||||||
this.server.destroy();
|
this.server.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
if (_.has(this, 'db')) {
|
if (_.has(this, 'db')) {
|
||||||
await this.db.destroy();
|
await this.db.destroy();
|
||||||
@ -417,10 +419,9 @@ class Strapi {
|
|||||||
// plugins bootstrap
|
// plugins bootstrap
|
||||||
const pluginBoostraps = Object.keys(this.plugins).map(plugin => {
|
const pluginBoostraps = Object.keys(this.plugins).map(plugin => {
|
||||||
return execBootstrap(_.get(this.plugins[plugin], 'config.functions.bootstrap')).catch(err => {
|
return execBootstrap(_.get(this.plugins[plugin], 'config.functions.bootstrap')).catch(err => {
|
||||||
// console.log(err);
|
|
||||||
strapi.log.error(`Bootstrap function in plugin "${plugin}" failed`);
|
strapi.log.error(`Bootstrap function in plugin "${plugin}" failed`);
|
||||||
strapi.log.error(err);
|
strapi.log.error(err);
|
||||||
// strapi.stop();
|
strapi.stop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await Promise.all(pluginBoostraps);
|
await Promise.all(pluginBoostraps);
|
||||||
@ -433,7 +434,7 @@ class Strapi {
|
|||||||
return execBootstrap(adminBootstrap).catch(err => {
|
return execBootstrap(adminBootstrap).catch(err => {
|
||||||
strapi.log.error(`Bootstrap function in admin failed`);
|
strapi.log.error(`Bootstrap function in admin failed`);
|
||||||
strapi.log.error(err);
|
strapi.log.error(err);
|
||||||
// strapi.stop();
|
strapi.stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user