feat: мини-истории, слово дня, меню практики
- Добавлены мини-истории для чтения с выбором жанра и вопросами - Кнопка показа/скрытия перевода истории - Количество вопросов берётся из настроек пользователя - Слово дня генерируется глобально в 00:00 UTC - Кнопка "Практика" открывает меню выбора режима - Убран автоматический create_all при запуске (только миграции) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
55
migrations/versions/20251209_add_mini_stories.py
Normal file
55
migrations/versions/20251209_add_mini_stories.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Add mini_stories table
|
||||
|
||||
Revision ID: 20251209_mini_stories
|
||||
Revises: 20251209_word_of_day
|
||||
Create Date: 2024-12-09
|
||||
|
||||
"""
|
||||
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 = '20251209_mini_stories'
|
||||
down_revision: Union[str, None] = '20251209_word_of_day'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Удаляем старую таблицу и enum если существуют
|
||||
op.execute("DROP TABLE IF EXISTS mini_stories CASCADE")
|
||||
op.execute("DROP TYPE IF EXISTS storygenre CASCADE")
|
||||
|
||||
# Создаём enum через raw SQL
|
||||
op.execute("CREATE TYPE storygenre AS ENUM ('dialogue', 'news', 'story', 'letter', 'recipe')")
|
||||
|
||||
# Создаём таблицу используя postgresql.ENUM с create_type=False
|
||||
story_genre = postgresql.ENUM('dialogue', 'news', 'story', 'letter', 'recipe', name='storygenre', create_type=False)
|
||||
|
||||
op.create_table(
|
||||
'mini_stories',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('title', sa.String(length=255), nullable=False),
|
||||
sa.Column('content', sa.String(length=5000), nullable=False),
|
||||
sa.Column('genre', story_genre, nullable=False),
|
||||
sa.Column('learning_lang', sa.String(length=5), nullable=False),
|
||||
sa.Column('level', sa.String(length=5), nullable=False),
|
||||
sa.Column('word_count', sa.Integer(), nullable=True, server_default='0'),
|
||||
sa.Column('vocabulary', sa.JSON(), nullable=True),
|
||||
sa.Column('questions', sa.JSON(), nullable=True),
|
||||
sa.Column('is_completed', sa.Boolean(), nullable=True, server_default='false'),
|
||||
sa.Column('correct_answers', sa.Integer(), nullable=True, server_default='0'),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('ix_mini_stories_user_id', 'mini_stories', ['user_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_mini_stories_user_id', table_name='mini_stories')
|
||||
op.drop_table('mini_stories')
|
||||
op.execute("DROP TYPE IF EXISTS storygenre CASCADE")
|
||||
26
migrations/versions/20251209_add_story_translation.py
Normal file
26
migrations/versions/20251209_add_story_translation.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Add translation field to mini_stories
|
||||
|
||||
Revision ID: 20251209_story_translation
|
||||
Revises: 20251209_mini_stories
|
||||
Create Date: 2025-12-09
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '20251209_story_translation'
|
||||
down_revision: Union[str, None] = '20251209_mini_stories'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column('mini_stories', sa.Column('translation', sa.String(5000), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('mini_stories', 'translation')
|
||||
50
migrations/versions/20251209_add_word_of_day.py
Normal file
50
migrations/versions/20251209_add_word_of_day.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Add word_of_day table (global by level)
|
||||
|
||||
Revision ID: 20251209_word_of_day
|
||||
Revises: 20251208_user_ai_model
|
||||
Create Date: 2024-12-09
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '20251209_word_of_day'
|
||||
down_revision: Union[str, None] = '20251208_user_ai_model'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Удаляем старую таблицу если существует (была с user_id)
|
||||
op.execute("DROP TABLE IF EXISTS word_of_day CASCADE")
|
||||
|
||||
op.create_table(
|
||||
'word_of_day',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('word', sa.String(length=255), nullable=False),
|
||||
sa.Column('transcription', sa.String(length=255), nullable=True),
|
||||
sa.Column('translation', sa.String(length=500), nullable=False),
|
||||
sa.Column('examples', sa.JSON(), nullable=True),
|
||||
sa.Column('synonyms', sa.String(length=500), nullable=True),
|
||||
sa.Column('etymology', sa.String(length=500), nullable=True),
|
||||
sa.Column('learning_lang', sa.String(length=5), nullable=False),
|
||||
sa.Column('level', sa.String(length=5), nullable=False),
|
||||
sa.Column('date', sa.DateTime(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('date', 'learning_lang', 'level', name='uq_wod_date_lang_level')
|
||||
)
|
||||
op.create_index('ix_word_of_day_learning_lang', 'word_of_day', ['learning_lang'], unique=False)
|
||||
op.create_index('ix_word_of_day_level', 'word_of_day', ['level'], unique=False)
|
||||
op.create_index('ix_word_of_day_date', 'word_of_day', ['date'], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_word_of_day_date', table_name='word_of_day')
|
||||
op.drop_index('ix_word_of_day_level', table_name='word_of_day')
|
||||
op.drop_index('ix_word_of_day_learning_lang', table_name='word_of_day')
|
||||
op.drop_table('word_of_day')
|
||||
Reference in New Issue
Block a user