"""classify_lang_script Revision ID: e5e21700527d Revises: cf8b451a9700 Create Date: 2020-06-25 11:32:38.491834 """ # revision identifiers, used by Alembic. revision = 'e5e21700527d' down_revision = 'cf8b451a9700' 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 else 0 end; $$; ''') def downgrade(): op.execute(''' drop function classify_lang_script(words text) ''')