Skip to content

Commit c081df3

Browse files
authoredFeb 19, 2025
HANA: Cleanup schemas of old tests (OSGeo#11869)
1 parent 05416ab commit c081df3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed
 

‎autotest/ogr/ogr_hana.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#
1212
# SPDX-License-Identifier: MIT
1313
###############################################################################
14+
from datetime import datetime, timedelta
1415
from os import environ
1516

1617
import gdaltest
@@ -48,8 +49,11 @@ def setup_driver():
4849
conn,
4950
"SELECT REPLACE(CURRENT_UTCDATE, '-', '') || '_' || BINTOHEX(SYSUUID) FROM DUMMY;",
5051
)
51-
gdaltest.hana_schema_name = "{}_{}".format("gdal_test", uid)
52+
schema_prefix = "gdal_test"
5253

54+
drop_old_test_schemas(conn, schema_prefix)
55+
56+
gdaltest.hana_schema_name = f"{schema_prefix}_{uid}"
5357
execute_sql(conn, f'CREATE SCHEMA "{gdaltest.hana_schema_name}"')
5458

5559
ds = open_datasource(1)
@@ -1375,6 +1379,24 @@ def execute_sql_scalar(conn, sql):
13751379
return res
13761380

13771381

1382+
def drop_old_test_schemas(conn, schema_prefix):
1383+
try:
1384+
assert conn
1385+
cursor = conn.cursor()
1386+
assert cursor
1387+
sql = f"""SELECT SCHEMA_NAME FROM SYS.SCHEMAS WHERE SCHEMA_NAME
1388+
LIKE '{schema_prefix.replace('_', '__')}__%' ESCAPE '_' AND
1389+
LOCALTOUTC(CREATE_TIME) < ?"""
1390+
cursor.execute(sql, datetime.now() - timedelta(days=1))
1391+
rows = cursor.fetchall()
1392+
cursor.close()
1393+
for row in rows:
1394+
execute_sql(conn, f'DROP SCHEMA "{row["SCHEMA_NAME"]}" CASCADE')
1395+
except Exception as ex:
1396+
print(f"Unable to drop old test schemas. Error: {ex}")
1397+
pass
1398+
1399+
13781400
def open_datasource(update=0, open_opts=None):
13791401
conn_str = "HANA:" + get_connection_str() + ";SCHEMA=" + gdaltest.hana_schema_name
13801402
if open_opts is None:

0 commit comments

Comments
 (0)
Failed to load comments.