Files
tg_bot_language/migrations/versions/20251208_add_ai_models.py

47 lines
1.6 KiB
Python
Raw Permalink Normal View History

"""Add ai_models table
Revision ID: 20251208_ai_models
Revises: 20251208_tasks_count
Create Date: 2024-12-08
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '20251208_ai_models'
down_revision: Union[str, None] = '20251208_tasks_count'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Создаём таблицу ai_models (enum aiprovider создаётся автоматически SQLAlchemy)
op.create_table(
'ai_models',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('provider', postgresql.ENUM('openai', 'google', name='aiprovider', create_type=False), nullable=False),
sa.Column('model_name', sa.String(length=100), nullable=False),
sa.Column('display_name', sa.String(length=100), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True, server_default='false'),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# Добавляем дефолтные модели
op.execute("""
INSERT INTO ai_models (provider, model_name, display_name, is_active, created_at)
VALUES
('openai', 'gpt-4o-mini', 'GPT-4o Mini', true, NOW()),
('openai', 'gpt-5-nano', 'GPT-5 Nano', false, NOW()),
('google', 'gemini-2.5-flash-lite', 'Gemini 2.5 Flash Lite', false, NOW())
""")
def downgrade() -> None:
op.drop_table('ai_models')