55Create Date: 2026-01-13 20:39:43.150557
66
77"""
8+
89from alembic import op
910import sqlalchemy as sa
1011from sqlalchemy .dialects import mysql
12+ from sqlalchemy import inspect
13+
1114
1215# revision identifiers, used by Alembic.
13- revision = ' 9ce4fca210b6'
14- down_revision = ' 30c4f4dbcb85'
16+ revision = " 9ce4fca210b6"
17+ down_revision = " 30c4f4dbcb85"
1518branch_labels = None
1619depends_on = None
1720
@@ -20,64 +23,99 @@ def upgrade() -> None:
2023 # ### commands auto generated by Alembic - please adjust! ###
2124 # Change scoring_parameters from JSON to Text (to match model definition)
2225 # Keep the comment as it provides useful documentation
23- op .alter_column ('contests' , 'scoring_parameters' ,
24- existing_type = mysql .JSON (),
25- type_ = sa .Text (),
26- comment = 'Weights for scoring parameters' ,
27- existing_comment = 'Weights for scoring parameters' ,
28- existing_nullable = True )
26+ op .alter_column (
27+ "contests" ,
28+ "scoring_parameters" ,
29+ existing_type = mysql .JSON (),
30+ type_ = sa .Text (),
31+ comment = "Weights for scoring parameters" ,
32+ existing_comment = "Weights for scoring parameters" ,
33+ existing_nullable = True ,
34+ )
2935 # Keep server default and comment for min_reference_count
30- op .alter_column ('contests' , 'min_reference_count' ,
31- existing_type = mysql .INTEGER (),
32- server_default = sa .text ("'0'" ),
33- comment = 'Minimum number of references required for article submissions' ,
34- existing_comment = 'Minimum number of references required for article submissions' ,
35- existing_nullable = False )
36+ op .alter_column (
37+ "contests" ,
38+ "min_reference_count" ,
39+ existing_type = mysql .INTEGER (),
40+ server_default = sa .text ("'0'" ),
41+ comment = "Minimum number of references required for article submissions" ,
42+ existing_comment = "Minimum number of references required for article submissions" ,
43+ existing_nullable = False ,
44+ )
3645 # Keep comment for organizers
37- op .alter_column ('contests' , 'organizers' ,
38- existing_type = mysql .TEXT (),
39- comment = 'Comma-separated list of organizer usernames' ,
40- existing_comment = 'Comma-separated list of organizer usernames' ,
41- existing_nullable = True )
46+ op .alter_column (
47+ "contests" ,
48+ "organizers" ,
49+ existing_type = mysql .TEXT (),
50+ comment = "Comma-separated list of organizer usernames" ,
51+ existing_comment = "Comma-separated list of organizer usernames" ,
52+ existing_nullable = True ,
53+ )
4254 # Change parameter_scores from JSON to Text (to match model definition)
4355 # Keep the comment as it provides useful documentation
44- op .alter_column ('submissions' , 'parameter_scores' ,
45- existing_type = mysql .JSON (),
46- type_ = sa .Text (),
47- comment = 'Per-parameter jury scores and comments' ,
48- existing_comment = 'Per-parameter jury scores and comments' ,
49- existing_nullable = True )
56+ op .alter_column (
57+ "submissions" ,
58+ "parameter_scores" ,
59+ existing_type = mysql .JSON (),
60+ type_ = sa .Text (),
61+ comment = "Per-parameter jury scores and comments" ,
62+ existing_comment = "Per-parameter jury scores and comments" ,
63+ existing_nullable = True ,
64+ )
5065 # Drop index that was detected as removed from model
51- op .drop_index (op .f ('idx_user_contest_submission' ), table_name = 'submissions' )
66+ # Drop index that was detected as removed from model (MySQL-safe)
67+ conn = op .get_bind ()
68+ inspector = inspect (conn )
69+
70+ indexes = [idx ["name" ] for idx in inspector .get_indexes ("submissions" )]
71+
72+ if "idx_user_contest_submission" in indexes :
73+ op .drop_index ("idx_user_contest_submission" , table_name = "submissions" )
5274 # ### end Alembic commands ###
5375
5476
5577def downgrade () -> None :
5678 # ### commands auto generated by Alembic - please adjust! ###
5779 # Recreate index that was dropped in upgrade
58- op .create_index (op .f ('idx_user_contest_submission' ), 'submissions' , ['user_id' , 'contest_id' ], unique = False )
80+ op .create_index (
81+ op .f ("idx_user_contest_submission" ),
82+ "submissions" ,
83+ ["user_id" , "contest_id" ],
84+ unique = False ,
85+ )
5986 # Revert parameter_scores back to JSON type
60- op .alter_column ('submissions' , 'parameter_scores' ,
61- existing_type = sa .Text (),
62- type_ = mysql .JSON (),
63- comment = 'Per-parameter jury scores and comments' ,
64- existing_nullable = True )
87+ op .alter_column (
88+ "submissions" ,
89+ "parameter_scores" ,
90+ existing_type = sa .Text (),
91+ type_ = mysql .JSON (),
92+ comment = "Per-parameter jury scores and comments" ,
93+ existing_nullable = True ,
94+ )
6595 # Revert organizers (no change needed, just keeping comment)
66- op .alter_column ('contests' , 'organizers' ,
67- existing_type = mysql .TEXT (),
68- comment = 'Comma-separated list of organizer usernames' ,
69- existing_nullable = True )
96+ op .alter_column (
97+ "contests" ,
98+ "organizers" ,
99+ existing_type = mysql .TEXT (),
100+ comment = "Comma-separated list of organizer usernames" ,
101+ existing_nullable = True ,
102+ )
70103 # Revert min_reference_count (keep default and comment)
71- op .alter_column ('contests' , 'min_reference_count' ,
72- existing_type = mysql .INTEGER (),
73- server_default = sa .text ("'0'" ),
74- comment = 'Minimum number of references required for article submissions' ,
75- existing_nullable = False )
104+ op .alter_column (
105+ "contests" ,
106+ "min_reference_count" ,
107+ existing_type = mysql .INTEGER (),
108+ server_default = sa .text ("'0'" ),
109+ comment = "Minimum number of references required for article submissions" ,
110+ existing_nullable = False ,
111+ )
76112 # Revert scoring_parameters back to JSON type
77- op .alter_column ('contests' , 'scoring_parameters' ,
78- existing_type = sa .Text (),
79- type_ = mysql .JSON (),
80- comment = 'Weights for scoring parameters' ,
81- existing_nullable = True )
113+ op .alter_column (
114+ "contests" ,
115+ "scoring_parameters" ,
116+ existing_type = sa .Text (),
117+ type_ = mysql .JSON (),
118+ comment = "Weights for scoring parameters" ,
119+ existing_nullable = True ,
120+ )
82121 # ### end Alembic commands ###
83-
0 commit comments