mirror of
https://github.com/GaMeNu/HFCNotificator.git
synced 2024-11-16 15:24:51 +02:00
v2.1.4
Updater to db 1.0.1
This commit is contained in:
parent
13c026137b
commit
1e69add653
@ -77,7 +77,7 @@ class DBAccess:
|
||||
self.connection = None
|
||||
log.warning(f"Couldn't connect to db. This is attempt #{i}")
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if self.connection is None:
|
||||
self.connection = mysql.connect(
|
||||
host='localhost',
|
||||
|
1
db_creation/__init__.py
Normal file
1
db_creation/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__version__ = '1.0.1'
|
@ -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
33
db_creation/update_db.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user