Skip to content

Commit

Permalink
Made the constraint detection case-insensitive (#4330)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpatel committed Mar 2, 2021
1 parent 5d2db21 commit a98614d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dialects/sqlite3/schema/ddl.js
Expand Up @@ -355,8 +355,8 @@ class SQLite3_DDL {
.map((line) => line.trim())
.filter((defLine) => {
if (
defLine.startsWith('constraint') === false &&
defLine.includes('foreign key') === false
defLine.toLowerCase().startsWith('constraint') === false &&
defLine.toLowerCase().includes('foreign key') === false
)
return true;

Expand Down
26 changes: 26 additions & 0 deletions test/integration2/schema/foreign-keys.spec.js
Expand Up @@ -195,6 +195,32 @@ describe('Schema', () => {
expect(err.message).to.include('constraint');
}
});

it('can drop added foreign keys in sqlite after a table rebuild', async () => {
if (!isSQLite(knex)) {
return;
}

await knex.schema.alterTable('foreign_keys_table_one', (table) => {
table
.foreign('fkey_three')
.references('foreign_keys_table_three.id');
});

await knex.schema.alterTable('foreign_keys_table_one', (table) => {
// In sqlite this rebuilds a new foreign_keys_table_one table
table.foreign('fkey_two').references('foreign_keys_table_two.id');
});

await knex.schema.alterTable('foreign_keys_table_one', (table) => {
table.dropForeign('fkey_three');
});

const fks = await knex.raw(
`PRAGMA foreign_key_list('foreign_keys_table_one');`
);
expect(fks.length).to.equal(1);
});
});
});
});
Expand Down

0 comments on commit a98614d

Please sign in to comment.