Browse Source

Добавился номер версии БД

pull/6/head
Alexei 2 years ago
parent
commit
ba34d8b632
  1. 51
      bot_modules/bd_version.py
  2. 2
      bot_modules/mod_simple_message.py
  3. 2
      bot_sys/bd_table.py
  4. 5
      main.py

51
bot_modules/bd_version.py

@ -0,0 +1,51 @@
# -*- coding: utf8 -*-
# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) <AlexeiBv+mirocod_platform_bot@narod.ru>
# Версия БД
# Этот модуль нужен для того, чтобы проводить миграции на новую версию. Он записывает в БД номер текущей версии.
from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes
from bot_modules import mod_table_operate, mod_simple_message
# ---------------------------------------------------------
# БД
module_name = 'bd_version'
table_name = module_name
base_version_number_field = 'baseVersionNumber'
sub_version_number_field = 'subVersionNumber'
table_base_version_number_field = bd_table.TableField(base_version_number_field, bd_table.TableFieldDestiny.VERSION_NUMBER, bd_table.TableFieldType.INT)
table_sub_version_number_field = bd_table.TableField(sub_version_number_field, bd_table.TableFieldDestiny.SUB_VERSION_NUMBER, bd_table.TableFieldType.INT)
table = bd_table.Table(table_name, [
table_base_version_number_field,
table_sub_version_number_field,
],
[
[table_base_version_number_field, table_sub_version_number_field],
])
init_access = f'{user_access.user_access_group_new}=-'
# ---------------------------------------------------------
# Сообщения и кнопки
button_names = {
}
messages = {
}
class ModuleBDVersion(mod_table_operate.TableOperateModule):
def __init__(self, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log):
super().__init__(table, messages, button_names, None, None, init_access, None, None, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log)
def GetName(self):
return module_name
def GetInitBDCommands(self):
return super(). GetInitBDCommands() + [
f"INSERT OR IGNORE INTO {table_name} ({base_version_number_field}, {sub_version_number_field}) VALUES ('{1}', '{0}');"
]

2
bot_modules/mod_simple_message.py

@ -84,6 +84,8 @@ class SimpleMessageModule(mod_interface.IModule):
def GetButtons(self, a_ModNameList):
buttons = []
if not a_ModNameList:
return buttons
for n in a_ModNameList:
m = self.m_ModuleAgregator.GetModule(n)
b = m.GetModuleButtons()

2
bot_sys/bd_table.py

@ -36,6 +36,8 @@ class TableFieldDestiny(Enum):
ITEM_ID = auto()
ADDRESS = auto()
OTHER = auto()
VERSION_NUMBER = auto()
SUB_VERSION_NUMBER = auto()
class TableField:
def __init__(self, a_Name, a_Destiny : TableFieldDestiny, a_Type : TableFieldType, a_Enum = None):

5
main.py

@ -7,6 +7,7 @@ from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_acces
from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments
from bot_modules import languages, messages, buttons, users, groups, user_in_groups
from bot_modules import orders, all_orders
from bot_modules import bd_version
from bot_sys import bot_subscribes
from bot_modules import subscribes
@ -106,6 +107,9 @@ child_mod_name_list = [mod_start_name]
mod_subscribe = subscribes.ModuleUserSubscribe(None, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_subscribe)
mod_bd_version = bd_version.ModuleBDVersion(g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_bd_version)
child_mod_name_list = [
mod_profile.GetName(),
mod_backup.GetName(),
@ -116,6 +120,7 @@ child_mod_name_list = [
mod_orders.GetName(),
mod_all_orders.GetName(),
mod_subscribe.GetName(),
mod_bd_version.GetName(),
]
mod_start = start.ModuleStart(child_mod_name_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_BotSubscribes, g_Log)
g_ModuleAgregator.AddModule(mod_start)

Loading…
Cancel
Save