Skip to content

Commit

Permalink
Merge branch 'hotfix/fix-fk-flaws'
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyFromPerion committed Aug 8, 2022
2 parents 31c05a5 + 2b14816 commit 5fa0c9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/ForeignKeyProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const processForeignKeyWorker = async (conversion: Conversion, tableName: string
);

if (row.CONSTRAINT_NAME in objConstraints) {
objConstraints[row.CONSTRAINT_NAME].column_name.push(`"${ currentColumnName }"`);
objConstraints[row.CONSTRAINT_NAME].referenced_column_name.push(`"${ currentReferencedColumnName }"`);
objConstraints[row.CONSTRAINT_NAME].column_name.add(`"${ currentColumnName }"`);
objConstraints[row.CONSTRAINT_NAME].referenced_column_name.add(`"${ currentReferencedColumnName }"`);
return;
}

objConstraints[row.CONSTRAINT_NAME] = Object.create(null);
objConstraints[row.CONSTRAINT_NAME].column_name = [`"${ currentColumnName }"`];
objConstraints[row.CONSTRAINT_NAME].referenced_column_name = [`"${ currentReferencedColumnName }"`];
objConstraints[row.CONSTRAINT_NAME].column_name = new Set<string>([`"${ currentColumnName }"`]);
objConstraints[row.CONSTRAINT_NAME].referenced_column_name = new Set<string>([`"${ currentReferencedColumnName }"`]);
objConstraints[row.CONSTRAINT_NAME].referenced_table_name = currentReferencedTableName;
objConstraints[row.CONSTRAINT_NAME].update_rule = row.UPDATE_RULE;
objConstraints[row.CONSTRAINT_NAME].delete_rule = row.DELETE_RULE;
Expand All @@ -71,9 +71,9 @@ const processForeignKeyWorker = async (conversion: Conversion, tableName: string

const constraintsPromises: Promise<void>[] = Object.keys(objConstraints).map(async (attr: string) => {
params.sql = `ALTER TABLE "${ conversion._schema }"."${ tableName }"
ADD FOREIGN KEY (${ objConstraints[attr].column_name.join(',') })
ADD FOREIGN KEY (${ [...objConstraints[attr].column_name].join(',') })
REFERENCES "${ conversion._schema }"."${ objConstraints[attr].referenced_table_name }"
(${ objConstraints[attr].referenced_column_name.join(',') })
(${ [...objConstraints[attr].referenced_column_name].join(',') })
ON UPDATE ${ objConstraints[attr].update_rule }
ON DELETE ${ objConstraints[attr].delete_rule };`;

Expand Down
5 changes: 4 additions & 1 deletion src/IndexAndKeyProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export default async (conversion: Conversion, tableName: string): Promise<void>
sqlAddIndex = `ALTER TABLE "${ conversion._schema }"."${ tableName }"
ADD PRIMARY KEY(${ objPgIndices[index].column_name.join(',') });`;
} else {
const columnName: string = objPgIndices[index].column_name[0].slice(1, -1);
const columnName: string = objPgIndices[index].column_name
.map((colName: string) => colName.slice(1, -1))
.join('_');

const indexName: string = getUniqueIdentifier(`${ tableName }_${ columnName }_idx`, '_idx');
sqlAddIndex = `CREATE ${ (objPgIndices[index].is_unique ? 'UNIQUE ' : '') }INDEX "${ indexName }"
ON "${ conversion._schema }"."${ tableName }"
Expand Down

0 comments on commit 5fa0c9b

Please sign in to comment.