Skip to content

Commit 7369f7d

Browse files
danghung-devJanny
authored and
Janny
committed
Fix cannot create foreignkey (#371)
1 parent b4078bb commit 7369f7d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/migration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ function mixinMigration(PostgreSQL) {
593593
// verify that the other model in the same DB
594594
if (this._models[fkEntityName]) {
595595
return 'CONSTRAINT ' + this.escapeName(fk.name) + ' ' +
596-
'FOREIGN KEY (' + fk.foreignKey + ') ' +
596+
'FOREIGN KEY (' + this.escapeName(fk.foreignKey) + ') ' +
597597
'REFERENCES ' + this.tableEscaped(fkEntityName) + '(' + fk.entityKey + ')';
598598
}
599599
}

test/postgresql.autoupdate.test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ describe('autoupdate', function() {
477477
'customerId': {
478478
'type': 'String',
479479
'length': 20,
480+
'postgresql': {
481+
'columnName': 'customerId',
482+
},
480483
},
481484
'description': {
482485
'type': 'String',
@@ -512,6 +515,9 @@ describe('autoupdate', function() {
512515
'customerId': {
513516
'type': 'String',
514517
'length': 20,
518+
'postgresql': {
519+
'columnName': 'customerId',
520+
},
515521
},
516522
'description': {
517523
'type': 'String',
@@ -521,6 +527,9 @@ describe('autoupdate', function() {
521527
'productId': {
522528
'type': 'String',
523529
'length': 20,
530+
'postgresql': {
531+
'columnName': 'productId',
532+
},
524533
},
525534
},
526535
};
@@ -557,6 +566,9 @@ describe('autoupdate', function() {
557566
'customerId': {
558567
'type': 'String',
559568
'length': 20,
569+
'postgresql': {
570+
'columnName': 'customerId',
571+
},
560572
},
561573
'description': {
562574
'type': 'String',
@@ -566,6 +578,9 @@ describe('autoupdate', function() {
566578
'productId': {
567579
'type': 'String',
568580
'length': 20,
581+
'postgresql': {
582+
'columnName': 'productId',
583+
},
569584
},
570585
},
571586
};
@@ -588,10 +603,16 @@ describe('autoupdate', function() {
588603
'customerId': {
589604
'type': 'String',
590605
'length': 20,
606+
'postgresql': {
607+
'columnName': 'customerId',
608+
},
591609
},
592610
'productId': {
593611
'type': 'String',
594612
'length': 20,
613+
'postgresql': {
614+
'columnName': 'productId',
615+
},
595616
},
596617
'description': {
597618
'type': 'String',
@@ -626,8 +647,7 @@ describe('autoupdate', function() {
626647
assert.equal(foreignKeys.length, 1);
627648
assert.equal(foreignKeys[0].pkColumnName, 'id');
628649
assert.equal(foreignKeys[0].pkTableName, 'customer_test3');
629-
// note: column names are converted to lowercase by postgres
630-
assert.equal(foreignKeys[0].fkColumnName, 'customerid');
650+
assert.equal(foreignKeys[0].fkColumnName, 'customerId');
631651
assert.equal(foreignKeys[0].fkName, 'fk_ordertest_customerId');
632652

633653
// update and add another fk
@@ -646,8 +666,7 @@ describe('autoupdate', function() {
646666
assert.equal(foreignKeysUpdated.length, 1);
647667
assert.equal(foreignKeysUpdated[0].pkColumnName, 'id');
648668
assert.equal(foreignKeysUpdated[0].pkTableName, 'customer_test2');
649-
// note: column names are converted to lowercase by postgres
650-
assert.equal(foreignKeysUpdated[0].fkColumnName, 'customerid');
669+
assert.equal(foreignKeysUpdated[0].fkColumnName, 'customerId');
651670
assert.equal(foreignKeysUpdated[0].fkName, 'fk_ordertest_customerId');
652671

653672
// create multiple fks on object

0 commit comments

Comments
 (0)