1+ """"resize url and slug columns to 191"
2+
3+ Revision ID: 878e287d2366
4+ Revises: 2f67b12600b4
5+ Create Date: 2025-10-08 09:08:35.363100
6+
7+ """
8+ from typing import Sequence , Union
9+
10+ from alembic import op
11+ import sqlalchemy as sa
12+ from sqlalchemy .dialects import mysql
13+
14+ # revision identifiers, used by Alembic.
15+ revision : str = '878e287d2366'
16+ down_revision : Union [str , Sequence [str ], None ] = '2f67b12600b4'
17+ branch_labels : Union [str , Sequence [str ], None ] = None
18+ depends_on : Union [str , Sequence [str ], None ] = None
19+
20+
21+ def upgrade () -> None :
22+ """Upgrade schema."""
23+ # Truncate existing values longer than 191 chars
24+ op .execute ("""
25+ UPDATE gateways
26+ SET slug = LEFT(slug, 191),
27+ url = LEFT(url, 191)
28+ WHERE LENGTH(slug) > 191 OR LENGTH(url) > 191;
29+ """ )
30+
31+ # Resize columns to String(191)
32+ op .alter_column (
33+ 'gateways' ,
34+ 'slug' ,
35+ existing_type = sa .String (length = 255 ),
36+ type_ = sa .String (length = 191 ),
37+ existing_nullable = False
38+ )
39+ op .alter_column (
40+ 'gateways' ,
41+ 'url' ,
42+ existing_type = sa .String (length = 767 ),
43+ type_ = sa .String (length = 191 ),
44+ existing_nullable = False
45+ )
46+
47+
48+ def downgrade () -> None :
49+ """Downgrade schema."""
50+ op .alter_column (
51+ 'gateways' ,
52+ 'slug' ,
53+ existing_type = sa .String (length = 191 ),
54+ type_ = sa .String (length = 255 ),
55+ existing_nullable = False
56+ )
57+ op .alter_column (
58+ 'gateways' ,
59+ 'url' ,
60+ existing_type = sa .String (length = 191 ),
61+ type_ = sa .String (length = 767 ),
62+ existing_nullable = False
63+ )
0 commit comments