-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigrate_media.py
More file actions
28 lines (23 loc) · 1.11 KB
/
migrate_media.py
File metadata and controls
28 lines (23 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import asyncio
import aiosqlite
DB_PATH = "bot.db"
async def migrate():
print(f"🔄 Начинаю медиа-миграцию {DB_PATH}...")
async with aiosqlite.connect(DB_PATH) as db:
try:
# 1. Добавляем content_type (по умолчанию 'text')
await db.execute("ALTER TABLE tasks ADD COLUMN content_type TEXT DEFAULT 'text'")
print("✅ Колонка 'content_type' добавлена.")
except Exception as e:
if "duplicate" in str(e): print("ℹ️ 'content_type' уже есть.")
else: print(f"❌ Ошибка content_type: {e}")
try:
# 2. Добавляем file_id (может быть NULL)
await db.execute("ALTER TABLE tasks ADD COLUMN file_id TEXT")
print("✅ Колонка 'file_id' добавлена.")
except Exception as e:
if "duplicate" in str(e): print("ℹ️ 'file_id' уже есть.")
else: print(f"❌ Ошибка file_id: {e}")
await db.commit()
if __name__ == "__main__":
asyncio.run(migrate())