@@ -95,32 +95,33 @@ def setUp(self):
95
95
# Added line break after scenario name
96
96
print ("" )
97
97
98
- # Create replication slot if it does not exist
99
- # for the RESQL test-cases of Subscriptions
100
- try :
101
- self .get_db_connection ()
102
- pg_cursor = self .connection .cursor ()
103
- pg_cursor .execute ("""
104
- SELECT 1 FROM pg_replication_slots
105
- WHERE slot_name = 'test_create_subscription'
106
- """ )
107
- exists = pg_cursor .fetchone ()
108
- if not exists :
98
+ # Create replication slot if it does not exist for the
99
+ # RESQL test-cases of Subscriptions for PGv17 and above
100
+ if self .server_information ['server_version' ] >= 170000 :
101
+ try :
102
+ self .get_db_connection ()
103
+ pg_cursor = self .connection .cursor ()
109
104
pg_cursor .execute ("""
110
- SELECT pg_create_logical_replication_slot(
111
- 'test_create_subscription',
112
- 'pgoutput',
113
- failover := false
114
- );
105
+ SELECT 1 FROM pg_replication_slots
106
+ WHERE slot_name = 'test_create_subscription'
115
107
""" )
116
- self .connection .commit ()
117
- print ("Replication slot 'test_create_subscription' created." )
118
- else :
119
- print ("Replication slot 'test_create_subscription' "
120
- "already exists." )
121
- pg_cursor .close ()
122
- except Exception as e :
123
- print ("Could not create replication slot: " , e )
108
+ exists = pg_cursor .fetchone ()
109
+ if not exists :
110
+ pg_cursor .execute ("""
111
+ SELECT pg_create_logical_replication_slot(
112
+ 'test_create_subscription',
113
+ 'pgoutput',
114
+ failover := false
115
+ );
116
+ """ )
117
+ self .connection .commit ()
118
+ print ("Replication slot 'test_create_subscription' created." )
119
+ else :
120
+ print ("Replication slot 'test_create_subscription' "
121
+ "already exists." )
122
+ pg_cursor .close ()
123
+ except Exception as e :
124
+ print ("Could not create replication slot: " , e )
124
125
125
126
def runTest (self ):
126
127
""" Create the module list on which reverse engineeredsql test
@@ -181,26 +182,27 @@ def runTest(self):
181
182
self .assertEqual (self .final_test_status , True )
182
183
183
184
def tearDown (self ):
184
- # Drop the replication slot created for the RESQL
185
- # test-cases of Subscriptions, if it exists before disconnecting
186
- try :
187
- self .get_db_connection ()
188
- pg_cursor = self .connection .cursor ()
189
- pg_cursor .execute ("""
190
- SELECT 1 FROM pg_replication_slots
191
- WHERE slot_name = 'test_create_subscription'
192
- """ )
193
- exists = pg_cursor .fetchone ()
194
- if exists :
185
+ # Drop the replication slot created for the RESQL test-cases of
186
+ # Subscriptions, if it exists before disconnecting for PGv17 and above
187
+ if self .server_information ['server_version' ] >= 170000 :
188
+ try :
189
+ self .get_db_connection ()
190
+ pg_cursor = self .connection .cursor ()
195
191
pg_cursor .execute ("""
196
- SELECT
197
- pg_drop_replication_slot( 'test_create_subscription');
192
+ SELECT 1 FROM pg_replication_slots
193
+ WHERE slot_name = 'test_create_subscription'
198
194
""" )
199
- self .connection .commit ()
200
- print ("Replication slot 'test_create_subscription' dropped." )
201
- pg_cursor .close ()
202
- except Exception as e :
203
- print ("Could not drop replication slot: " , e )
195
+ exists = pg_cursor .fetchone ()
196
+ if exists :
197
+ pg_cursor .execute ("""
198
+ SELECT
199
+ pg_drop_replication_slot('test_create_subscription');
200
+ """ )
201
+ self .connection .commit ()
202
+ print ("Replication slot 'test_create_subscription' dropped." )
203
+ pg_cursor .close ()
204
+ except Exception as e :
205
+ print ("Could not drop replication slot: " , e )
204
206
205
207
database_utils .disconnect_database (
206
208
self , self .server_information ['server_id' ],
0 commit comments