From 650fb7b2d71139b0e857c8b1b4a6d1b0bfced52e Mon Sep 17 00:00:00 2001 From: Alexey Masterov Date: Mon, 9 Sep 2024 16:18:26 +0200 Subject: [PATCH] Drop subscriptions if exist --- .../cloud_regress/test_cloud_regress.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test_runner/cloud_regress/test_cloud_regress.py b/test_runner/cloud_regress/test_cloud_regress.py index abb30054a8..ea15908fee 100644 --- a/test_runner/cloud_regress/test_cloud_regress.py +++ b/test_runner/cloud_regress/test_cloud_regress.py @@ -30,6 +30,28 @@ def test_cloud_regress( log.info("Creating the extension") cur.execute("CREATE EXTENSION IF NOT EXISTS regress_so") conn.commit() + log.info("Looking for subscriptions in the regress database") + cur.execute( + "SELECT subname FROM pg_catalog.pg_subscription WHERE " + "subdbid = (SELECT oid FROM pg_catalog.pg_database WHERE datname='regression');" + ) + if cur.rowcount > 0: + with psycopg2.connect( + dbname="regression", + host=remote_pg.default_options["host"], + user=remote_pg.default_options["user"], + password=remote_pg.default_options["password"], + ) as regress_conn: + with regress_conn.cursor() as regress_cur: + for sub in cur: + regress_cur.execute(f"ALTER SUBSCRIPTION {sub[0]} DISABLE") + regress_cur.execute( + f"ALTER SUBSCRIPTION {sub[0]} SET (slot_name = NONE)" + ) + regress_cur.execute( + f"DROP SUBSCRIPTION {sub[0]} SET (slot_name = NONE)" + ) + regress_conn.commit() # This is also a workaround for the full path problem # If we specify the full path in the command, the library won't be downloaded