mirror of
https://github.com/strapi/strapi.git
synced 2025-08-28 02:35:55 +00:00
Fix PR feedback
This commit is contained in:
parent
054df448a9
commit
f545f373aa
@ -46,4 +46,4 @@
|
|||||||
"npm": ">= 3.0.0"
|
"npm": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
@ -48,4 +48,4 @@
|
|||||||
"react-select": "^1.0.0-rc.5",
|
"react-select": "^1.0.0-rc.5",
|
||||||
"strapi-helper-plugin": "3.0.0-alpha.7.3"
|
"strapi-helper-plugin": "3.0.0-alpha.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,4 +48,4 @@
|
|||||||
"npm": ">= 3.0.0"
|
"npm": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
@ -46,4 +46,4 @@
|
|||||||
"npm": ">= 3.0.0"
|
"npm": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
@ -45,4 +45,4 @@
|
|||||||
"npm": ">= 3.0.0"
|
"npm": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
@ -48,4 +48,4 @@
|
|||||||
"npm": ">= 3.0.0"
|
"npm": ">= 3.0.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
@ -235,93 +235,87 @@ module.exports = {
|
|||||||
syncSchema: (cb) => {
|
syncSchema: (cb) => {
|
||||||
const Model = strapi.plugins['users-permissions'].models.user;
|
const Model = strapi.plugins['users-permissions'].models.user;
|
||||||
|
|
||||||
if (Model.orm === 'bookshelf') {
|
if (Model.orm !== 'bookshelf') {
|
||||||
const tableName = Model.collectionName;
|
return cb();
|
||||||
|
}
|
||||||
|
|
||||||
let queue = new Promise((resolve, reject) => {
|
const tableName = Model.collectionName;
|
||||||
strapi.connections[Model.connection].schema.hasTable(tableName)
|
|
||||||
.then(exist => {
|
new Promise((resolve, reject) => {
|
||||||
if (!exist) {
|
strapi.connections[Model.connection].schema.hasTable(tableName)
|
||||||
strapi.log.warn(`
|
.then(exist => {
|
||||||
|
if (!exist) {
|
||||||
|
strapi.log.warn(`
|
||||||
⚠️ TABLE \`${tableName}\` DOESN'T EXIST
|
⚠️ TABLE \`${tableName}\` DOESN'T EXIST
|
||||||
|
|
||||||
1️⃣ EXECUTE THE FOLLOWING SQL QUERY
|
1️⃣ EXECUTE THE FOLLOWING SQL QUERY
|
||||||
|
|
||||||
CREATE TABLE "${tableName}" (
|
CREATE TABLE "${tableName}" (
|
||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
username text,
|
username text,
|
||||||
email text,
|
email text,
|
||||||
role text,
|
role text,
|
||||||
"resetPasswordToken" text,
|
"resetPasswordToken" text,
|
||||||
password text,
|
password text,
|
||||||
updated_at timestamp with time zone,
|
updated_at timestamp with time zone,
|
||||||
created_at timestamp with time zone
|
created_at timestamp with time zone
|
||||||
);
|
);
|
||||||
|
|
||||||
2️⃣ RESTART YOUR SERVER
|
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(() => {
|
let commands = '';
|
||||||
const attributes = _.cloneDeep(Model.attributes);
|
|
||||||
attributes.id = {
|
|
||||||
type: 'integer'
|
|
||||||
};
|
|
||||||
attributes.updated_at = attributes.created_at = {
|
|
||||||
type: 'timestamp with time zone'
|
|
||||||
};
|
|
||||||
|
|
||||||
let commands = '';
|
const columnExist = (description, attribute) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const columnExist = (description, attribute) => {
|
strapi.connections[Model.connection].schema.hasColumn(tableName, attribute)
|
||||||
return new Promise((resolve, reject) => {
|
.then(exist => {
|
||||||
strapi.connections[Model.connection].schema.hasColumn(tableName, attribute)
|
if (!exist) {
|
||||||
.then(exist => {
|
if (description.type === 'string') {
|
||||||
if (!exist) {
|
description.type = 'text';
|
||||||
if (description.type === 'string') {
|
|
||||||
description.type = 'text';
|
|
||||||
}
|
|
||||||
|
|
||||||
commands += `\r\nALTER TABLE "${tableName}" ADD "${attribute}" ${description.type};`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
const testsColumns = Object.entries(attributes).map(([attribute, description]) => columnExist(description, attribute));
|
||||||
.then(() => {
|
Promise.all(testsColumns)
|
||||||
if (!_.isEmpty(commands)) {
|
.then(() => {
|
||||||
strapi.log.warn(`
|
if (!_.isEmpty(commands)) {
|
||||||
|
strapi.log.warn(`
|
||||||
⚠️ TABLE \`${tableName}\` HAS MISSING COLUMNS
|
⚠️ TABLE \`${tableName}\` HAS MISSING COLUMNS
|
||||||
|
|
||||||
1️⃣ EXECUTE THE FOLLOWING SQL QUERIES
|
1️⃣ EXECUTE THE FOLLOWING SQL QUERIES
|
||||||
${commands}
|
${commands}
|
||||||
|
|
||||||
2️⃣ RESTART YOUR SERVER
|
2️⃣ RESTART YOUR SERVER
|
||||||
`);
|
`);
|
||||||
|
|
||||||
strapi.stop();
|
strapi.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
cb();
|
cb();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
cb();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user