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

[Sqlite3] Fix can not get table sql because of case sensitive #5509

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function renameTable(tableName, alteredName) {
}

function getTableSql(tableName) {
return `SELECT type, sql FROM sqlite_master WHERE (type='table' OR (type='index' AND sql IS NOT NULL)) AND tbl_name='${tableName}'`;
return `SELECT type, sql FROM sqlite_master WHERE (type='table' OR (type='index' AND sql IS NOT NULL)) AND lower(tbl_name)='${tableName.toLowerCase()}'`;
}

function isForeignCheckEnabled() {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@
],
"exclude": [
"lib/dialects/oracle",
"lib/dialects/oracledb"
"lib/dialects/oracledb",
"test/**/*.spec.js"
]
},
"tsd": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exports.up = async (knex) => {
await knex.schema.createTableIfNotExists('some_table', (table) => {
table.increments();
});
};

exports.down = async (knex) => {
await knex.schema.dropTableIfExists('some_table');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.up = async (knex) => {
// Use the same table but different case.
await knex.schema.table('Some_Table', (table) => {
table.string('other_id').after('id');
table.string('name').after('other_id');
});
};

exports.down = async (knex) => {
await knex.schema.table('Some_Table', (table) => {
table.dropColumns('other_id', 'name');
});
};
25 changes: 25 additions & 0 deletions test/integration2/migrate/migration-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ describe('Migrations', function () {
await db.migrate.rollback();
await knexInstance.destroy();
});

it('should not fail alter-table-ignore-case-sensitive', async () => {
await knex.migrate.latest({
directory:
'test/integration2/migrate/alter-table-ignore-case-sensitive',
});
expect(await knex.schema.hasColumn('Some_Table', 'id')).to.be.true;
expect(await knex.schema.hasColumn('Some_Table', 'other_id')).to.be
.true;
expect(await knex.schema.hasColumn('Some_Table', 'name')).to.be
.true;
// try different case
expect(await knex.schema.hasColumn('some_table', 'id')).to.be.true;
expect(await knex.schema.hasColumn('some_table', 'other_id')).to.be
.true;
expect(await knex.schema.hasColumn('some_table', 'name')).to.be
.true;

await knex.migrate.rollback({
directory:
'test/integration2/migrate/alter-table-ignore-case-sensitive',
});
expect(await knex.schema.hasTable('Some_Table')).to.be.false;
expect(await knex.schema.hasTable('some_table')).to.be.false;
});
}

it('should not fail drop-and-recreate-column operation when using async/await', () => {
Expand Down