[grafana] Adjust scripts for SQLAlchemy 2.0 compatibility

* wrap statements with `text()` where appropriate
* add commit handling for explicit transactions
* replace deprecated .execute() usage with SQLAlchemy 2.0 syntax

Change-Id: If528ed9240ede4478aba53249f0bfe2be41d8769
Signed-off-by: Arina Stebenkova <astebenkova@mirantis.com>
This commit is contained in:
Arina Stebenkova
2025-07-04 19:20:56 +03:00
committed by Alexey
parent 85569c271a
commit 0a60ab7ed8
2 changed files with 18 additions and 9 deletions

View File

@@ -11,7 +11,7 @@
import os
import sys
import logging
from sqlalchemy import create_engine
from sqlalchemy import create_engine, text
# Create logger, console handler and formatter
logger = logging.getLogger('OpenStack-Helm DB Init')
@@ -58,13 +58,18 @@ except:
# Create Table
try:
user_engine.execute('''CREATE TABLE IF NOT EXISTS `session` (
`key`CHAR(16) NOT NULL,
`data` BLOB,
`expiry` INT(11) UNSIGNED NOT NULL,
PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;''')
with user_engine.connect() as conn:
conn.execute(text('''CREATE TABLE IF NOT EXISTS `session` (
`key` CHAR(16) NOT NULL,
`data` BLOB,
`expiry` INT(11) UNSIGNED NOT NULL,
PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;'''))
try:
conn.commit()
except AttributeError:
pass
logger.info('Created table for session cache')
except:
logger.critical('Could not create table for session cache')
except Exception as e:
logger.critical(f'Could not create table for session cache: {e}')
raise

View File

@@ -0,0 +1,4 @@
---
grafana:
- Adjust Python code for SQLAlchemy 2.0 compatibility
...