refactor MediaGroup. Add database
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import os
|
||||
from helper_bot.utils.base_dependency_factory import BaseDependencyFactory
|
||||
|
||||
# Получаем текущий рабочий каталог
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
from database.db import BotDB
|
||||
|
||||
# Переходим на уровень выше, чтобы выйти из папки migrations/
|
||||
# Получаем текущую директорию
|
||||
current_dir = os.path.dirname(__file__)
|
||||
|
||||
# Переходим на уровень выше
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
|
||||
# Строим путь до файла
|
||||
tg_bot_database_path = os.path.join(parent_dir, "tg-bot-database")
|
||||
|
||||
bdf = BaseDependencyFactory()
|
||||
BotDB = bdf.get_db()
|
||||
BotDB = BotDB(parent_dir, 'database/tg-bot-database')
|
||||
|
||||
|
||||
def get_filename():
|
||||
@@ -32,5 +29,6 @@ def main():
|
||||
BotDB.create_table(migrations_init)
|
||||
BotDB.update_version(0, get_filename())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import os
|
||||
from helper_bot.utils.base_dependency_factory import BaseDependencyFactory
|
||||
|
||||
bdf = BaseDependencyFactory()
|
||||
BotDB = bdf.get_db()
|
||||
from database.db import BotDB
|
||||
|
||||
# Получаем текущую директорию
|
||||
current_dir = os.path.dirname(__file__)
|
||||
|
||||
# Переходим на уровень выше
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
|
||||
BotDB = BotDB(parent_dir, 'database/tg-bot-database')
|
||||
|
||||
|
||||
def get_filename():
|
||||
|
||||
60
migrations/002_create_tables_media_group.py
Normal file
60
migrations/002_create_tables_media_group.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
|
||||
from database.db import BotDB
|
||||
|
||||
# Получаем текущую директорию
|
||||
current_dir = os.path.dirname(__file__)
|
||||
|
||||
# Переходим на уровень выше
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
|
||||
BotDB = BotDB(parent_dir, 'database/tg-bot-database')
|
||||
|
||||
|
||||
def get_filename():
|
||||
"""Возвращает имя файла без расширения."""
|
||||
filename = os.path.basename(__file__)
|
||||
filename = os.path.splitext(filename)[0]
|
||||
return filename
|
||||
|
||||
|
||||
def main():
|
||||
# Проверка версии миграций
|
||||
current_version = BotDB.get_current_version() # Добавьте функцию для получения версии
|
||||
|
||||
# Выполнение миграций и проверка последней версии
|
||||
if current_version < 2:
|
||||
# Скрипты миграции
|
||||
create_table_sql_1 = """
|
||||
CREATE TABLE IF NOT EXISTS "post_from_telegram_suggest"
|
||||
(
|
||||
message_id INTEGER not null,
|
||||
text TEXT,
|
||||
helper_text_message_id INTEGER,
|
||||
author_id INTEGER,
|
||||
created_at TEXT
|
||||
);
|
||||
"""
|
||||
create_table_sql_2 = """
|
||||
CREATE TABLE IF NOT EXISTS message_link_to_content (
|
||||
post_id INTEGER NOT NULL,
|
||||
message_id INTEGER NOT NULL
|
||||
);
|
||||
"""
|
||||
create_table_sql_3 = """
|
||||
CREATE TABLE IF NOT EXISTS content_post_from_telegram (
|
||||
message_id INTEGER NOT NULL,
|
||||
content_name TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
# Применение миграции
|
||||
BotDB.create_table(create_table_sql_1)
|
||||
BotDB.create_table(create_table_sql_2)
|
||||
BotDB.create_table(create_table_sql_3)
|
||||
filename = get_filename()
|
||||
|
||||
BotDB.update_version(2, filename)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user