Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unify and fix tests queryGenerator.arithmeticQuery/dropTableQuery/showIndexesQuery/describeTableQuery #15235

Merged
merged 25 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
abc2789
meta: unify queryGenerator.arithmeticQuery tests
WikiRik Nov 4, 2022
e24af3a
meta: unify queryGenerator.dropTableQuery tests
WikiRik Nov 4, 2022
ccacacf
meta: unify queryGenerator.dropTableQuery cascade tests
WikiRik Nov 4, 2022
ff61b38
meta: unify queryGenerator.createTableQuery tests
WikiRik Nov 4, 2022
d2e713a
meta: unify queryGenerator.showIndexesQuery tests
WikiRik Nov 5, 2022
4f6d068
fix: improve dropTableQuery
WikiRik Nov 5, 2022
ea9e4ec
meta: add showIndexesQuery types
WikiRik Nov 5, 2022
1c7c5b6
Revert "meta: unify queryGenerator.createTableQuery tests"
WikiRik Nov 5, 2022
956237d
meta: fix sqlite unit tests
WikiRik Nov 5, 2022
47291e4
meta: reduce skipped tests
WikiRik Nov 5, 2022
bbf8331
meta: not pass options.cascade to dropTableQuery when not supported […
WikiRik Nov 5, 2022
5f768c7
Merge branch 'main' into WikiRik/query-generator-unit-tests-refactor
WikiRik Nov 5, 2022
e01d3ad
meta: add describeTableQuery tests
WikiRik Nov 5, 2022
e0fd934
fix: add support for tableName object in describeTableQuery for final…
WikiRik Nov 5, 2022
d8b784d
Merge branch 'main' into WikiRik/query-generator-unit-tests-refactor
WikiRik Nov 6, 2022
21af3c2
meta: implement review suggestions
WikiRik Nov 10, 2022
85ad38f
Merge branch 'main' into WikiRik/query-generator-unit-tests-refactor
WikiRik Nov 10, 2022
8c9788c
fix(mssql): fix ifExists
WikiRik Nov 10, 2022
3a8a57b
fix(mssql): undo changes to removeColumnQuery
WikiRik Nov 10, 2022
7d3099d
meta: only cascade when supported
WikiRik Nov 10, 2022
7bbd64d
Update test/unit/query-generator/arithmetic-query.test.ts
WikiRik Nov 16, 2022
2f17e6e
meta: implement review comments
WikiRik Nov 16, 2022
9847be0
Merge branch 'main' into WikiRik/query-generator-unit-tests-refactor
WikiRik Nov 16, 2022
11939bc
meta: implement _dropAllTables suggestion and add unit test
WikiRik Nov 16, 2022
ccbdf1e
meta: add integration test
WikiRik Nov 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/dialects/abstract/query-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class QueryInterface {
* @returns {Promise}
*/
async dropTable(tableName, options = {}) {
options.cascade = (options.cascade && this.queryGenerator.dialect.supports.dropTable.cascade) ? options.cascade
options.cascade = options.cascade !== null ? options.cascade
ephys marked this conversation as resolved.
Show resolved Hide resolved
// TODO: dropTable should not accept a "force" option, `sync()` should set `cascade` itself if its force option is true
: (options.force && this.queryGenerator.dialect.supports.dropTable.cascade) ? true
: undefined;
Expand All @@ -290,7 +290,12 @@ export class QueryInterface {
for (const tableName of tableNames) {
// if tableName is not in the Array of tables names then don't drop it
if (!skip.includes(tableName.tableName || tableName)) {
await this.dropTable(tableName, { ...options, cascade: true });
await this.dropTable(tableName, {
// enable "cascade" by default if supported by this dialect,
// but let the user override the default
cascade: this.queryGenerator.dialect.supports.dropTable.cascade ? true : undefined,
...options,
});
}
}
}
Expand Down
24 changes: 0 additions & 24 deletions test/integration/sequelize/drop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,4 @@ describe('Sequelize#drop', () => {
// drop both tables
await sequelize.drop();
});

it('supports truncating cyclic associations with { cascade: true }', async () => {
WikiRik marked this conversation as resolved.
Show resolved Hide resolved
const A = sequelize.define('A', {
BId: {
type: DataTypes.INTEGER,
},
});

const B = sequelize.define('B', {
AId: {
type: DataTypes.INTEGER,
},
});

// These models both have a foreign key that references the other model.
// Sequelize should be able to create them.
A.belongsTo(B, { foreignKey: { allowNull: false } });
B.belongsTo(A, { foreignKey: { allowNull: false } });

await sequelize.sync();

// drop both tables
await sequelize.drop({ cascade: true });
});
});
27 changes: 27 additions & 0 deletions test/unit/query-interface/drop-table.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { expectsql, getTestDialect, sequelize } from '../../support';

const dialectName = getTestDialect();

describe('QueryInterface#dropTable', () => {
afterEach(() => {
sinon.restore();
});

it('produces a DROP TABLE query with cascade', async () => {
if (sequelize.dialect.supports.dropTable.cascade) {
const stub = sinon.stub(sequelize, 'queryRaw');

await sequelize.getQueryInterface().dropTable('myTable', { cascade: true });

expect(stub.callCount).to.eq(1);
const firstCall = stub.getCall(0);
expectsql(firstCall.args[0] as string, {
default: 'DROP TABLE IF EXISTS [myTable] CASCADE;',
});
} else {
await expect(sequelize.getQueryInterface().dropTable('myTable', { cascade: true })).to.be.rejectedWith(`The following options are not supported by dropTableQuery in ${dialectName}: cascade`);
}
});
});