From b6dfa4259220b1a0f9189d1bfe071b6e4a615b5a Mon Sep 17 00:00:00 2001 From: GaMeNu <98153342+GaMeNu@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:26:49 +0300 Subject: [PATCH] v2.2.0 RELEASE! Small bugfix 2.2 --- db_creation/update_db.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/db_creation/update_db.py b/db_creation/update_db.py index 50dc0e1..3627d22 100644 --- a/db_creation/update_db.py +++ b/db_creation/update_db.py @@ -13,10 +13,22 @@ DB_PASSWORD = os.getenv('DB_PASSWORD') def updater_1_0_0(connection: mysql.connection.MySQLConnection) -> str: - crsr = connection.cursor() - crsr.execute("ALTER TABLE `hfc_db`.`channels` DROP COLUMN IF EXISTS locations") - crsr.execute("ALTER TABLE `hfc_db`.`channels` ADD COLUMN `locations` JSON NOT NULL DEFAULT ('[]');") - crsr.close() + with connection.cursor() as crsr: + crsr.execute("SELECT COLUMN_NAME " + "FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE TABLE_SCHEMA = 'hfc_db' " + "AND TABLE_NAME = 'channels' " + "AND COLUMN_NAME = 'locations';") + + exists = (crsr.fetchone() is not None) + + crsr.nextset() + + if exists: + crsr.execute("ALTER TABLE `hfc_db`.`channels` DROP COLUMN `locations`;") + + crsr.execute("ALTER TABLE `hfc_db`.`channels` ADD COLUMN `locations` JSON NOT NULL DEFAULT ('[]');") + return '1.0.1'