Fix PR feedback

This commit is contained in:
Jim Laurie 2018-01-11 15:00:34 +01:00
parent 054df448a9
commit f545f373aa
7 changed files with 60 additions and 66 deletions

View File

@ -46,4 +46,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -48,4 +48,4 @@
"react-select": "^1.0.0-rc.5",
"strapi-helper-plugin": "3.0.0-alpha.7.3"
}
}
}

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -46,4 +46,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -45,4 +45,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -48,4 +48,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
}

View File

@ -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();
}
});
}
};