Skip to content

Commit

Permalink
HANA: Cleanup schemas of old tests (#11869)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrylov authored Feb 19, 2025
1 parent 05416ab commit c081df3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion autotest/ogr/ogr_hana.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
# SPDX-License-Identifier: MIT
###############################################################################
from datetime import datetime, timedelta
from os import environ

import gdaltest
Expand Down Expand Up @@ -48,8 +49,11 @@ def setup_driver():
conn,
"SELECT REPLACE(CURRENT_UTCDATE, '-', '') || '_' || BINTOHEX(SYSUUID) FROM DUMMY;",
)
gdaltest.hana_schema_name = "{}_{}".format("gdal_test", uid)
schema_prefix = "gdal_test"

drop_old_test_schemas(conn, schema_prefix)

gdaltest.hana_schema_name = f"{schema_prefix}_{uid}"
execute_sql(conn, f'CREATE SCHEMA "{gdaltest.hana_schema_name}"')

ds = open_datasource(1)
Expand Down Expand Up @@ -1375,6 +1379,24 @@ def execute_sql_scalar(conn, sql):
return res


def drop_old_test_schemas(conn, schema_prefix):
try:
assert conn
cursor = conn.cursor()
assert cursor
sql = f"""SELECT SCHEMA_NAME FROM SYS.SCHEMAS WHERE SCHEMA_NAME
LIKE '{schema_prefix.replace('_', '__')}__%' ESCAPE '_' AND
LOCALTOUTC(CREATE_TIME) < ?"""
cursor.execute(sql, datetime.now() - timedelta(days=1))
rows = cursor.fetchall()
cursor.close()
for row in rows:
execute_sql(conn, f'DROP SCHEMA "{row["SCHEMA_NAME"]}" CASCADE')
except Exception as ex:
print(f"Unable to drop old test schemas. Error: {ex}")
pass


def open_datasource(update=0, open_opts=None):
conn_str = "HANA:" + get_connection_str() + ";SCHEMA=" + gdaltest.hana_schema_name
if open_opts is None:
Expand Down

0 comments on commit c081df3

Please sign in to comment.