Updater to db 1.0.1
This commit is contained in:
GaMeNu 2023-10-16 22:52:02 +03:00
parent 13c026137b
commit 1e69add653
4 changed files with 37 additions and 2 deletions

1
db_creation/__init__.py Normal file
View File

@ -0,0 +1 @@
__version__ = '1.0.1'

View File

@ -1,6 +1,5 @@
import json
import os
import time
import mysql.connector as mysql
import requests
@ -82,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `hfc_db`.`channels` (
`channel_id` BIGINT(8) UNSIGNED NOT NULL,
`server_id` BIGINT(8) UNSIGNED NULL,
`channel_lang` VARCHAR(15) NOT NULL,
`locations` JSON NULL,
PRIMARY KEY (`channel_id`),
UNIQUE INDEX `channel_id_UNIQUE` (`channel_id` ASC) VISIBLE,
CONSTRAINT `server_id`
@ -114,6 +114,7 @@ BEGIN
END IF;
END$$
DELIMITER ;
SET SQL_MODE=@OLD_SQL_MODE;

33
db_creation/update_db.py Normal file
View File

@ -0,0 +1,33 @@
import os
from dotenv import load_dotenv
import db_creation
import mysql.connector as mysql
target_version = db_creation.__version__
load_dotenv()
DB_USERNAME = os.getenv('DB_USERNAME')
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` ADD COLUMN `locations` JSON NULL;')
crsr.close()
return '1.0.1'
updaters = {
'1.0.0': updater_1_0_0
}
current_version = input('Please enter current version:\n')
if current_version not in updaters.keys():
print('Invalid version.')
exit()
with mysql.connect(host='localhost', user=DB_USERNAME, password=DB_PASSWORD) as connection:
while current_version != target_version:
current_version = updaters[current_version](connection)