From 1cb8dbe795660c713ebf7f683707435ca0720836 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 15 Apr 2021 17:42:39 +0200 Subject: [PATCH] Update migration routine --- cps/config_sql.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index 6e1ff54e..6e13489d 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -21,15 +21,16 @@ from __future__ import division, print_function, unicode_literals import os import sys -from sqlalchemy import exc, Column, String, Integer, SmallInteger, Boolean, BLOB, JSON +from sqlalchemy import Column, String, Integer, SmallInteger, Boolean, BLOB, JSON from sqlalchemy.exc import OperationalError +from sqlalchemy.sql.expression import text try: # Compatibility with sqlalchemy 2.0 from sqlalchemy.orm import declarative_base except ImportError: from sqlalchemy.ext.declarative import declarative_base -from . import constants, cli, logger, ub +from . import constants, cli, logger log = logger.create() @@ -368,17 +369,17 @@ def _migrate_table(session, orm_class): column_default = "" else: if isinstance(column.default.arg, bool): - column_default = ("DEFAULT %r" % int(column.default.arg)) + column_default = "DEFAULT {}".format(int(column.default.arg)) else: - column_default = ("DEFAULT '%r'" % column.default.arg) + column_default = "DEFAULT `{}`".format(column.default.arg) if isinstance(column.type, JSON): column_type = "JSON" else: column_type = column.type - alter_table = "ALTER TABLE %s ADD COLUMN `%s` %s %s" % (orm_class.__tablename__, + alter_table = text("ALTER TABLE %s ADD COLUMN `%s` %s %s" % (orm_class.__tablename__, column_name, column_type, - column_default) + column_default)) log.debug(alter_table) session.execute(alter_table) changed = True