diff --git a/lib/migration.js b/lib/migration.js index 95c57b1d..526d0de6 100644 --- a/lib/migration.js +++ b/lib/migration.js @@ -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'; @@ -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') {