Skip to content

Commit

Permalink
Eliminate redundant calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ewrayjohnson committed Apr 13, 2022
1 parent 1517b87 commit 04edca5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function mixinMigration(PostgreSQL) {
const userModel = model.registry.getModelByType('User').modelName;
const modelName = model.modelName;
const tableName = self.table(modelName);
let _foreignKeys = settings.foreignKeys || {};
let _foreignKeys = settings.foreignKeys;

Object.defineProperty(settings, 'foreignKeys', {
get: () => {
if (_foreignKeys) {
return _foreignKeys;
}
_foreignKeys = _foreignKeys || {};
function addForeignKey(keyFrom, modelTo, keyTo) {
const foreignColumn = self.column(modelName, keyFrom);
const constraintName = tableName + '_' + foreignColumn + '_fkey';
Expand Down Expand Up @@ -71,9 +75,13 @@ function mixinMigration(PostgreSQL) {
}
});

let _indexes = settings.indexes || {};
let _indexes = settings.indexes;
Object.defineProperty(settings, 'indexes', {
get: () => {
if (_indexes) {
return _indexes;
}
_indexes = _indexes || {};
let fkRefKeys = [];
for (const rel of Object.values(m.model.relations)) {
if (rel.type === 'belongsTo') {
Expand Down

0 comments on commit 04edca5

Please sign in to comment.