* Used instead of sync() when two models reference each-other, so their foreign keys cannot be created immediately. * * @param {object} options - sync options * @private
(options)
| 840 | * @private |
| 841 | */ |
| 842 | async _syncModelsWithCyclicReferences(options) { |
| 843 | if (this.dialect.name === 'sqlite') { |
| 844 | // Optimisation: no need to do this in two passes in SQLite because we can temporarily disable foreign keys |
| 845 | await withSqliteForeignKeysOff(this, options, async () => { |
| 846 | for (const model of this.modelManager.models) { |
| 847 | await model.sync(options); |
| 848 | } |
| 849 | }); |
| 850 | |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | // create all tables, but don't create foreign key constraints |
| 855 | for (const model of this.modelManager.models) { |
| 856 | await model.sync({ ...options, withoutForeignKeyConstraints: true }); |
| 857 | } |
| 858 | |
| 859 | // add foreign key constraints |
| 860 | for (const model of this.modelManager.models) { |
| 861 | await model.sync({ ...options, force: false, alter: true }); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * Truncate all tables defined through the sequelize models. |
no test coverage detected