diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index 97c1ce886a..1b2c1a4e61 100755 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -46,4 +46,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-content-manager/package.json b/packages/strapi-plugin-content-manager/package.json index 45305737ea..8f2b962c50 100755 --- a/packages/strapi-plugin-content-manager/package.json +++ b/packages/strapi-plugin-content-manager/package.json @@ -48,4 +48,4 @@ "react-select": "^1.0.0-rc.5", "strapi-helper-plugin": "3.0.0-alpha.7.3" } -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-content-type-builder/package.json b/packages/strapi-plugin-content-type-builder/package.json index b45d524f83..0efeda6297 100755 --- a/packages/strapi-plugin-content-type-builder/package.json +++ b/packages/strapi-plugin-content-type-builder/package.json @@ -48,4 +48,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-email/package.json b/packages/strapi-plugin-email/package.json index a7626e623a..02994be080 100644 --- a/packages/strapi-plugin-email/package.json +++ b/packages/strapi-plugin-email/package.json @@ -46,4 +46,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-settings-manager/package.json b/packages/strapi-plugin-settings-manager/package.json index 160aea9120..92805a489b 100755 --- a/packages/strapi-plugin-settings-manager/package.json +++ b/packages/strapi-plugin-settings-manager/package.json @@ -45,4 +45,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-users-permissions/package.json b/packages/strapi-plugin-users-permissions/package.json index caad2303e5..5f557e9fbe 100644 --- a/packages/strapi-plugin-users-permissions/package.json +++ b/packages/strapi-plugin-users-permissions/package.json @@ -48,4 +48,4 @@ "npm": ">= 3.0.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js index 7eb799cc01..6657c99ea3 100644 --- a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js +++ b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js @@ -235,93 +235,87 @@ module.exports = { syncSchema: (cb) => { const Model = strapi.plugins['users-permissions'].models.user; - if (Model.orm === 'bookshelf') { - const tableName = Model.collectionName; + if (Model.orm !== 'bookshelf') { + return cb(); + } - let queue = new Promise((resolve, reject) => { - strapi.connections[Model.connection].schema.hasTable(tableName) - .then(exist => { - if (!exist) { - strapi.log.warn(` + const tableName = Model.collectionName; + + new Promise((resolve, reject) => { + strapi.connections[Model.connection].schema.hasTable(tableName) + .then(exist => { + if (!exist) { + strapi.log.warn(` ⚠️ TABLE \`${tableName}\` DOESN'T EXIST 1️⃣ EXECUTE THE FOLLOWING SQL QUERY CREATE TABLE "${tableName}" ( - id integer NOT NULL, - username text, - email text, - role text, - "resetPasswordToken" text, - password text, - updated_at timestamp with time zone, - created_at timestamp with time zone + id integer NOT NULL, + username text, + email text, + role text, + "resetPasswordToken" text, + password text, + updated_at timestamp with time zone, + created_at timestamp with time zone ); 2️⃣ RESTART YOUR SERVER - `); + `); - strapi.stop(); - } + strapi.stop(); + } - resolve(); - }); + resolve(); }); + }) + .then(() => { + const attributes = _.cloneDeep(Model.attributes); + attributes.id = { + type: 'integer' + }; + attributes.updated_at = attributes.created_at = { + type: 'timestamp with time zone' + }; - queue = queue.then(() => { - const attributes = _.cloneDeep(Model.attributes); - attributes.id = { - type: 'integer' - }; - attributes.updated_at = attributes.created_at = { - type: 'timestamp with time zone' - }; + let commands = ''; - let commands = ''; - - const columnExist = (description, attribute) => { - return new Promise((resolve, reject) => { - strapi.connections[Model.connection].schema.hasColumn(tableName, attribute) - .then(exist => { - if (!exist) { - if (description.type === 'string') { - description.type = 'text'; - } - - commands += `\r\nALTER TABLE "${tableName}" ADD "${attribute}" ${description.type};`; + const columnExist = (description, attribute) => { + return new Promise((resolve, reject) => { + strapi.connections[Model.connection].schema.hasColumn(tableName, attribute) + .then(exist => { + if (!exist) { + if (description.type === 'string') { + description.type = 'text'; } - resolve(); - }); + commands += `\r\nALTER TABLE "${tableName}" ADD "${attribute}" ${description.type};`; + } + + resolve(); }); - }; - - const testsColumns = []; - - _.forEach(attributes, (description, attribute) => { - testsColumns.push(columnExist(description, attribute)); }); + }; - Promise.all(testsColumns) - .then(() => { - if (!_.isEmpty(commands)) { - strapi.log.warn(` + const testsColumns = Object.entries(attributes).map(([attribute, description]) => columnExist(description, attribute)); + Promise.all(testsColumns) + .then(() => { + if (!_.isEmpty(commands)) { + strapi.log.warn(` ⚠️ TABLE \`${tableName}\` HAS MISSING COLUMNS 1️⃣ EXECUTE THE FOLLOWING SQL QUERIES ${commands} 2️⃣ RESTART YOUR SERVER - `); + `); - strapi.stop(); - } + strapi.stop(); + } - cb(); - }); + cb(); }); - } else { - cb(); - } + }); } };