Some checks failed
Deploy to Production / Build and Deploy (push) Has been cancelled
The previous migration used revision 'a1b2c3d4e5f6' which was already taken by 005_add_reset_token_to_users.py, causing a cycle. Also both f6a7b8c9d0e1 and the new migration pointed to the same down_revision. Fixed: - New unique revision ID: b7c8d9e0f1a2 - down_revision points to f6a7b8c9d0e1 (current head) - Chain: e5b2c9d1f4a8 → f6a7b8c9d0e1 → b7c8d9e0f1a2 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""Set multilingual glossaries target_language to 'multi'
|
|
|
|
Revision ID: b7c8d9e0f1a2
|
|
Revises: f6a7b8c9d0e1
|
|
Create Date: 2026-05-31
|
|
|
|
Glossary templates that were enriched with multilingual translations
|
|
(via enrich_glossary_templates.py) contain translations for 11 languages
|
|
(de, es, it, pt, nl, ru, ja, ko, zh, ar, fa) in each term's translations
|
|
field. These should be marked as target_language='multi' instead of 'en'.
|
|
|
|
This migration detects glossaries whose terms have multilingual translations
|
|
and sets their target_language to 'multi'.
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers
|
|
revision = "b7c8d9e0f1a2"
|
|
down_revision = "f6a7b8c9d0e1"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Glossaries with terms containing 5+ translation keys are multilingual templates
|
|
# (enriched glossaries have 11 translations: de, es, it, pt, nl, ru, ja, ko, zh, ar, fa)
|
|
op.execute("""
|
|
UPDATE glossaries
|
|
SET target_language = 'multi'
|
|
WHERE id IN (
|
|
SELECT DISTINCT g.id
|
|
FROM glossaries g
|
|
JOIN glossary_terms gt ON gt.glossary_id = g.id
|
|
WHERE gt.translations IS NOT NULL
|
|
AND jsonb_typeof(gt.translations) = 'object'
|
|
AND (
|
|
SELECT count(*)
|
|
FROM jsonb_object_keys(gt.translations)
|
|
) >= 5
|
|
)
|
|
""")
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Revert multilingual glossaries back to 'en'
|
|
op.execute("""
|
|
UPDATE glossaries
|
|
SET target_language = 'en'
|
|
WHERE target_language = 'multi'
|
|
""")
|