From b61c5f789342ecc4d330a20cdccc5524c01b9433 Mon Sep 17 00:00:00 2001 From: David Martos Date: Wed, 20 Nov 2024 15:58:42 +0100 Subject: [PATCH 1/2] test for issue 390 --- test/v3_test.dart | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/v3_test.dart b/test/v3_test.dart index 73c4959..67368a3 100644 --- a/test/v3_test.dart +++ b/test/v3_test.dart @@ -470,6 +470,39 @@ void main() { expect(isClosed, isTrue); }); }); + + withPostgresServer('issue 390', (server) { + test( + 'issue 390 - Cannot ALTER TABLE because it is being used by active queries in this session', + () async { + final conn = await server.newConnection(); + const tableToAlter = 'table_to_alter'; + const otherTable = 'other_table'; + + await conn.execute(''' + CREATE TABLE $tableToAlter ( + a_id INTEGER PRIMARY KEY NOT NULL, + a_other_id INTEGER NOT NULL + );'''); + + await conn.execute( + 'CREATE TABLE $otherTable (other_id INTEGER PRIMARY KEY NOT NULL);'); + + await conn.runTx((tx) async { + // Select from the table that will be altered + await tx.execute('SELECT * FROM $tableToAlter;'); + + // Add a foreign key constraint + await tx.execute(''' + ALTER TABLE $tableToAlter + ADD CONSTRAINT fk_other + FOREIGN KEY (a_other_id) + REFERENCES $otherTable(other_id);'''); + }); + + // Should not throw + }); + }); } final _isPostgresException = isA(); From e285f10a7f3a2b903317e88c87aad9d81065f9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Wed, 20 Nov 2024 17:53:31 +0100 Subject: [PATCH 2/2] Update test/v3_test.dart --- test/v3_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/v3_test.dart b/test/v3_test.dart index 67368a3..6fa201e 100644 --- a/test/v3_test.dart +++ b/test/v3_test.dart @@ -501,7 +501,7 @@ void main() { }); // Should not throw - }); + }, skip: 'investigation needed'); }); }