Files
FileAudioAPI/init_db.py
T
poturaevpetr ebfb48a2b8 create tables
2025-12-25 22:14:58 +05:00

40 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Скрипт для инициализации базы данных
Создаёт все необходимые таблицы
"""
from apiApp.database import Base, engine
from sqlalchemy import inspect
def init_database():
"""Создаёт все таблицы в базе данных"""
print("🔧 Инициализация базы данных...")
# Проверяем существующие таблицы
inspector = inspect(engine)
existing_tables = inspector.get_table_names()
if existing_tables:
print(f"📋 Существующие таблицы: {', '.join(existing_tables)}")
# Создаём все таблицы
Base.metadata.create_all(bind=engine)
# Проверяем результат
inspector = inspect(engine)
all_tables = inspector.get_table_names()
print(f"✅ Создано таблиц: {len(all_tables)}")
for table in all_tables:
print(f" - {table}")
return all_tables
if __name__ == "__main__":
try:
tables = init_database()
print(f"\n🎉 База данных готова! Создано таблиц: {len(tables)}")
except Exception as e:
print(f"\n❌ Ошибка при создании таблиц: {e}")
exit(1)