* Drop all tables defined through this sequelize instance. * This is done by calling Model.drop on each model. * * @see * Model.drop for options * * @param {object} [options] The options passed to each call to Model.drop * @param {boolean|Function} [options.logging] A fu
(options)
| 912 | * @returns {Promise} |
| 913 | */ |
| 914 | async drop(options) { |
| 915 | // if 'cascade' is specified, we don't have to worry about cyclic dependencies. |
| 916 | if (options && options.cascade) { |
| 917 | for (const model of this.modelManager.models) { |
| 918 | await model.drop(options); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | const sortedModels = this.modelManager.getModelsTopoSortedByForeignKey(); |
| 923 | |
| 924 | // no cyclic dependency between models, we can delete them in an order that will not cause an error. |
| 925 | if (sortedModels) { |
| 926 | for (const model of sortedModels) { |
| 927 | await model.drop(options); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | if (this.dialect.name === 'sqlite') { |
| 932 | // Optimisation: no need to do this in two passes in SQLite because we can temporarily disable foreign keys |
| 933 | await withSqliteForeignKeysOff(this, options, async () => { |
| 934 | for (const model of this.modelManager.models) { |
| 935 | await model.drop(options); |
| 936 | } |
| 937 | }); |
| 938 | |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | // has cyclic dependency: we first remove each foreign key, then delete each model. |
| 943 | for (const model of this.modelManager.models) { |
| 944 | const tableName = model.getTableName(); |
| 945 | const foreignKeys = await this.queryInterface.getForeignKeyReferencesForTable(tableName, options); |
| 946 | |
| 947 | await Promise.all(foreignKeys.map(foreignKey => { |
| 948 | return this.queryInterface.removeConstraint(tableName, foreignKey.constraintName, options); |
| 949 | })); |
| 950 | } |
| 951 | |
| 952 | for (const model of this.modelManager.models) { |
| 953 | await model.drop(options); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Test the connection by trying to authenticate. It runs `SELECT 1+1 AS result` query. |
no test coverage detected