[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:
@@ -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
|
||||
|
||||
4
releasenotes/notes/grafana-b3fac6a311d115a6.yaml
Normal file
4
releasenotes/notes/grafana-b3fac6a311d115a6.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
grafana:
|
||||
- Adjust Python code for SQLAlchemy 2.0 compatibility
|
||||
...
|
||||
Reference in New Issue
Block a user