Skip to content

Commit

Permalink
Add test for SQLite foreign key constraints falsely firing when alter…
Browse files Browse the repository at this point in the history
…ing a table
  • Loading branch information
nickrum committed Dec 13, 2021
1 parent d6ea66e commit 970e2bb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/integration2/schema/foreign-keys.spec.js
Expand Up @@ -264,6 +264,31 @@ describe('Schema', () => {
);
expect(fks.length).to.equal(1);
});

it('can alter a table in sqlite while another table has a foreign key constraint on this table', async () => {
if (!isSQLite(knex)) {
return;
}

await knex.schema.alterTable('foreign_keys_table_two', (table) => {
table.integer('alter_column');
});
await knex.schema.alterTable('foreign_keys_table_one', (table) => {
table.foreign('fkey_two').references('foreign_keys_table_two.id');
});

await knex('foreign_keys_table_two').insert({ alter_column: 1 });
await knex('foreign_keys_table_one').insert({
fkey_two: 1,
fkey_three: 1,
});

await expect(
knex.schema.alterTable('foreign_keys_table_two', (table) => {
table.dropColumn('alter_column');
})
).to.not.be.eventually.rejected;
});
});

describe('Schema (Foreign keys)', () => {
Expand Down

0 comments on commit 970e2bb

Please sign in to comment.