mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 11:25:17 +00:00
Fix PG queries
This commit is contained in:
parent
04c3518dbc
commit
462b44a759
@ -414,6 +414,7 @@ module.exports = {
|
|||||||
for (let index = 0; index < hasTables.length; ++index) {
|
for (let index = 0; index < hasTables.length; ++index) {
|
||||||
const hasTable = hasTables[index];
|
const hasTable = hasTables[index];
|
||||||
const currentModel = Object.keys(details)[index];
|
const currentModel = Object.keys(details)[index];
|
||||||
|
const quote = details[currentModel].client === 'pg' ? '"' : '`';
|
||||||
|
|
||||||
if (!hasTable) {
|
if (!hasTable) {
|
||||||
missingTables.push(`
|
missingTables.push(`
|
||||||
@ -423,13 +424,13 @@ module.exports = {
|
|||||||
case 'user':
|
case 'user':
|
||||||
tablesToCreate.push(`
|
tablesToCreate.push(`
|
||||||
|
|
||||||
CREATE TABLE \`${details[currentModel].tableName}\` (
|
CREATE TABLE ${quote}${details[currentModel].tableName}${quote} (
|
||||||
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
||||||
username text,
|
username text,
|
||||||
email text,
|
email text,
|
||||||
provider text,
|
provider text,
|
||||||
role text,
|
role ${details[currentModel].client === 'pg' ? 'integer' : 'int'},
|
||||||
${details[currentModel].client === 'pg' ? '\`resetPasswordToken\`' : 'resetPasswordToken'} text,
|
${quote}resetPasswordToken${quote} text,
|
||||||
password text,
|
password text,
|
||||||
updated_at ${details[currentModel].client === 'pg' ? 'timestamp with time zone' : 'timestamp'},
|
updated_at ${details[currentModel].client === 'pg' ? 'timestamp with time zone' : 'timestamp'},
|
||||||
created_at ${details[currentModel].client === 'pg' ? 'timestamp with time zone' : 'timestamp'}
|
created_at ${details[currentModel].client === 'pg' ? 'timestamp with time zone' : 'timestamp'}
|
||||||
@ -438,7 +439,7 @@ CREATE TABLE \`${details[currentModel].tableName}\` (
|
|||||||
case 'role':
|
case 'role':
|
||||||
tablesToCreate.push(`
|
tablesToCreate.push(`
|
||||||
|
|
||||||
CREATE TABLE \`${details[currentModel].tableName}\` (
|
CREATE TABLE ${quote}${details[currentModel].tableName}${quote} (
|
||||||
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
||||||
name text,
|
name text,
|
||||||
description text,
|
description text,
|
||||||
@ -448,7 +449,7 @@ CREATE TABLE \`${details[currentModel].tableName}\` (
|
|||||||
case 'permission':
|
case 'permission':
|
||||||
tablesToCreate.push(`
|
tablesToCreate.push(`
|
||||||
|
|
||||||
CREATE TABLE \`${details[currentModel].tableName}\` (
|
CREATE TABLE ${quote}${details[currentModel].tableName}${quote} (
|
||||||
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
id ${details[currentModel].client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
|
||||||
role ${details[currentModel].client === 'pg' ? 'integer' : 'int'},
|
role ${details[currentModel].client === 'pg' ? 'integer' : 'int'},
|
||||||
type text,
|
type text,
|
||||||
@ -483,6 +484,7 @@ CREATE TABLE \`${details[currentModel].tableName}\` (
|
|||||||
|
|
||||||
for (let index = 0; index < hasTables.length; ++index) {
|
for (let index = 0; index < hasTables.length; ++index) {
|
||||||
const currentModel = Object.keys(details)[index];
|
const currentModel = Object.keys(details)[index];
|
||||||
|
const quote = details[currentModel].client === 'pg' ? '"' : '`';
|
||||||
const attributes = {
|
const attributes = {
|
||||||
id: {
|
id: {
|
||||||
type: details[currentModel].client === 'pg' ? 'integer' : 'int'
|
type: details[currentModel].client === 'pg' ? 'integer' : 'int'
|
||||||
@ -514,7 +516,7 @@ CREATE TABLE \`${details[currentModel].tableName}\` (
|
|||||||
const attribute = attributes[currentColumn];
|
const attribute = attributes[currentColumn];
|
||||||
|
|
||||||
if (!hasColumn && !attribute.collection) {
|
if (!hasColumn && !attribute.collection) {
|
||||||
const currentType = attribute.type || attribute.model;
|
const currentType = attribute.model ? 'integer' : attribute.type;
|
||||||
const type = currentType === 'string' ? 'text' : currentType;
|
const type = currentType === 'string' ? 'text' : currentType;
|
||||||
|
|
||||||
missingColumns.push(`
|
missingColumns.push(`
|
||||||
@ -522,7 +524,7 @@ CREATE TABLE \`${details[currentModel].tableName}\` (
|
|||||||
|
|
||||||
tablesToAlter.push(`
|
tablesToAlter.push(`
|
||||||
|
|
||||||
ALTER TABLE \`${details[currentModel].tableName}\` ADD ${details[currentModel].client === 'pg' ? `\`${currentColumn}\`` : `${currentColumn}`} ${type};`);
|
ALTER TABLE ${quote}${details[currentModel].tableName}${quote} ADD ${details[currentModel].client === 'pg' ? `${quote}${currentColumn}${quote}` : `${currentColumn}`} ${type};`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user