fix(db): make migrations and glossary index SQLite-compatible
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m57s

This commit is contained in:
2026-06-14 19:01:07 +02:00
parent cb8ce697d2
commit adc3583358
6 changed files with 93 additions and 35 deletions

View File

@@ -26,23 +26,44 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
conn = op.get_bind()
dialect = conn.dialect.name
# 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
)
""")
if dialect == "sqlite":
# SQLite does not have jsonb_object_keys. Use json_each for compatibility.
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 json_type(gt.translations, '$') = 'object'
AND (
SELECT count(*)
FROM json_each(gt.translations)
) >= 5
)
""")
else:
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
)
""")
# Also rename glossaries: replace "Anglais" with "Multilingue" in the name
op.execute("""