不要怂,就是干,撸起袖子干!

Commit 8b53f721 by João Eiras Committed by Sushant

fix(showTablesQuery): ignore views for mssql/mysql (#11439)

1 parent 992ddf75
......@@ -222,7 +222,7 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
}
showTablesQuery() {
return 'SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES;';
return "SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';";
}
dropTableQuery(tableName) {
......
......@@ -149,7 +149,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
}
showTablesQuery() {
return 'SHOW TABLES;';
return "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';";
}
addColumnQuery(table, key, dataType) {
......
......@@ -41,6 +41,30 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
});
});
describe('showAllTables', () => {
it('should not contain views', function() {
const cleanup = () => {
// NOTE: The syntax "DROP VIEW [IF EXISTS]"" is not part of the standard
// and might not be available on all RDBMSs. Therefore "DROP VIEW" is
// the compatible option, which can throw an error in case the VIEW does
// not exist. In case of error, it is ignored by reflect()+tap().
return this.sequelize.query('DROP VIEW V_Fail').reflect();
};
return this.queryInterface
.createTable('my_test_table', { name: DataTypes.STRING })
.tap(cleanup)
.then(() => this.sequelize.query('CREATE VIEW V_Fail AS SELECT 1 Id'))
.then(() => this.queryInterface.showAllTables())
.tap(cleanup)
.then(tableNames => {
if (tableNames[0] && tableNames[0].tableName) {
tableNames = tableNames.map(v => v.tableName);
}
expect(tableNames).to.deep.equal(['my_test_table']);
});
});
});
describe('renameTable', () => {
it('should rename table', function() {
return this.queryInterface
......
......@@ -183,7 +183,7 @@ if (current.dialect.name === 'mssql') {
it('showTablesQuery', function() {
expectsql(this.queryGenerator.showTablesQuery(), {
mssql: 'SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES;'
mssql: "SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';"
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!