"""add_hebrew_classify Revision ID: d442e6552298 Revises: 249d4700d767 Create Date: 2020-07-17 11:10:19.248456 """ # revision identifiers, used by Alembic. revision = 'd442e6552298' down_revision = '249d4700d767' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa def upgrade(): op.execute(''' create or replace function classify_lang_script(words text) returns integer strict language sql as $$ select case when words ~* '[\u0400-\u04FF]' then 1 -- cyrillic when words ~* '[\u0600-\u06FF]' then 2 -- arabic when words ~* '[\u4E00-\u9FFF]' then 3 -- cjk when words ~* '[\u0E00-\u0E7F]' then 4 -- thai when words ~* '[\u0590-\u05FF]' then 5 -- hebrew else 0 end; $$; ''') def downgrade(): op.execute(''' create or replace function classify_lang_script(words text) returns integer strict language sql as $$ select case when words ~* '[\u0400-\u04FF]' then 1 -- cyrillic when words ~* '[\u0600-\u06FF]' then 2 -- arabic when words ~* '[\u4E00-\u9FFF]' then 3 -- cjk when words ~* '[\u0E00-\u0E7F]' then 4 -- thai else 0 end; $$; ''')