style: isort + black

This commit is contained in:
2026-02-02 00:13:33 +03:00
parent 5f66c86d99
commit 561c9074dd
86 changed files with 8459 additions and 5793 deletions

View File

@@ -1,11 +1,13 @@
"""Репозиторий для работы с миграциями базы данных."""
import aiosqlite
from database.base import DatabaseConnection
class MigrationRepository(DatabaseConnection):
"""Репозиторий для управления миграциями базы данных."""
async def create_table(self):
"""Создает таблицу migrations, если она не существует."""
query = """
@@ -17,13 +19,15 @@ class MigrationRepository(DatabaseConnection):
"""
await self._execute_query(query)
self.logger.info("Таблица migrations создана или уже существует")
async def get_applied_migrations(self) -> list[str]:
"""Возвращает список имен примененных скриптов миграций."""
conn = None
try:
conn = await self._get_connection()
cursor = await conn.execute("SELECT script_name FROM migrations ORDER BY applied_at")
cursor = await conn.execute(
"SELECT script_name FROM migrations ORDER BY applied_at"
)
rows = await cursor.fetchall()
await cursor.close()
return [row[0] for row in rows]
@@ -33,15 +37,14 @@ class MigrationRepository(DatabaseConnection):
finally:
if conn:
await conn.close()
async def is_migration_applied(self, script_name: str) -> bool:
"""Проверяет, применена ли миграция."""
conn = None
try:
conn = await self._get_connection()
cursor = await conn.execute(
"SELECT COUNT(*) FROM migrations WHERE script_name = ?",
(script_name,)
"SELECT COUNT(*) FROM migrations WHERE script_name = ?", (script_name,)
)
row = await cursor.fetchone()
await cursor.close()
@@ -52,15 +55,14 @@ class MigrationRepository(DatabaseConnection):
finally:
if conn:
await conn.close()
async def mark_migration_applied(self, script_name: str) -> None:
"""Отмечает миграцию как примененную."""
conn = None
try:
conn = await self._get_connection()
await conn.execute(
"INSERT INTO migrations (script_name) VALUES (?)",
(script_name,)
"INSERT INTO migrations (script_name) VALUES (?)", (script_name,)
)
await conn.commit()
self.logger.info(f"Миграция {script_name} отмечена как примененная")
@@ -72,7 +74,7 @@ class MigrationRepository(DatabaseConnection):
finally:
if conn:
await conn.close()
async def create_table_from_sql(self, sql_script: str) -> None:
"""Создает таблицу из SQL скрипта. Используется в миграциях."""
await self._execute_query(sql_script)