Fixing an issue I found with postgres schema generator, it was applying all primary keys to all tables.
This commit is contained in:
parent
e141a17e87
commit
b3f3826aa6
|
@ -1,9 +1,17 @@
|
||||||
SELECT 'CREATE DATABASE main'
|
SELECT 'CREATE DATABASE main'
|
||||||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
||||||
CREATE TABLE Persons (
|
CREATE TABLE Persons (
|
||||||
PersonID int NOT NULL PRIMARY KEY,
|
PersonID INT NOT NULL PRIMARY KEY,
|
||||||
LastName varchar(255),
|
LastName varchar(255),
|
||||||
FirstName varchar(255),
|
FirstName varchar(255),
|
||||||
Address varchar(255),
|
Address varchar(255),
|
||||||
City varchar(255)
|
City varchar(255)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE Tasks (
|
||||||
|
TaskID INT NOT NULL PRIMARY KEY,
|
||||||
|
PersonID INT,
|
||||||
|
TaskName varchar(255),
|
||||||
|
CONSTRAINT fkPersons
|
||||||
|
FOREIGN KEY(PersonID)
|
||||||
|
REFERENCES Persons(PersonID)
|
||||||
|
);
|
||||||
|
|
|
@ -118,15 +118,18 @@ class PostgresIntegration extends Sql {
|
||||||
* @param {*} datasourceId - datasourceId to fetch
|
* @param {*} datasourceId - datasourceId to fetch
|
||||||
*/
|
*/
|
||||||
async buildSchema(datasourceId) {
|
async buildSchema(datasourceId) {
|
||||||
let keys = []
|
let tableKeys = {}
|
||||||
try {
|
try {
|
||||||
const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL)
|
const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL)
|
||||||
for (let table of primaryKeysResponse.rows) {
|
for (let table of primaryKeysResponse.rows) {
|
||||||
keys.push(table.column_name || table.primary_key)
|
const tableName = table.table_name
|
||||||
|
if (!tableKeys[tableName]) {
|
||||||
|
tableKeys[tableName] = []
|
||||||
|
}
|
||||||
|
tableKeys[tableName].push(table.column_name || table.primary_key)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// TODO: this try catch method isn't right
|
tableKeys = {}
|
||||||
keys = ["id"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const columnsResponse = await this.client.query(this.COLUMNS_SQL)
|
const columnsResponse = await this.client.query(this.COLUMNS_SQL)
|
||||||
|
@ -140,7 +143,7 @@ class PostgresIntegration extends Sql {
|
||||||
if (!tables[tableName]) {
|
if (!tables[tableName]) {
|
||||||
tables[tableName] = {
|
tables[tableName] = {
|
||||||
_id: buildExternalTableId(datasourceId, tableName),
|
_id: buildExternalTableId(datasourceId, tableName),
|
||||||
primary: keys,
|
primary: tableKeys[tableName] || ["id"],
|
||||||
name: tableName,
|
name: tableName,
|
||||||
schema: {},
|
schema: {},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue