@@ -165,6 +165,7 @@ def inject_user_date_format():
165165
166166 # Automatic database migration for existing installations
167167 try :
168+ from sqlalchemy import text
168169 inspector = db .inspect (db .engine )
169170
170171 # Check UserSettings table for missing columns
@@ -173,20 +174,26 @@ def inject_user_date_format():
173174
174175 if 'last_notification_sent' not in user_settings_columns :
175176 print ("🔄 Auto-migrating: Adding last_notification_sent column to user_settings..." )
176- db .engine .execute ('ALTER TABLE user_settings ADD COLUMN last_notification_sent DATE' )
177+ with db .engine .connect () as conn :
178+ conn .execute (text ('ALTER TABLE user_settings ADD COLUMN last_notification_sent DATE' ))
179+ conn .commit ()
177180 migrations_applied .append ("last_notification_sent" )
178181
179182 if 'notification_time' not in user_settings_columns :
180183 print ("🔄 Auto-migrating: Adding notification_time column to user_settings..." )
181- db .engine .execute ('ALTER TABLE user_settings ADD COLUMN notification_time INTEGER DEFAULT 9' )
184+ with db .engine .connect () as conn :
185+ conn .execute (text ('ALTER TABLE user_settings ADD COLUMN notification_time INTEGER DEFAULT 9' ))
186+ conn .commit ()
182187 migrations_applied .append ("notification_time" )
183188
184189 # Check Subscription table for missing columns
185190 subscription_columns = [col ['name' ] for col in inspector .get_columns ('subscription' )]
186191
187192 if 'custom_notification_days' not in subscription_columns :
188193 print ("🔄 Auto-migrating: Adding custom_notification_days column to subscription..." )
189- db .engine .execute ('ALTER TABLE subscription ADD COLUMN custom_notification_days INTEGER' )
194+ with db .engine .connect () as conn :
195+ conn .execute (text ('ALTER TABLE subscription ADD COLUMN custom_notification_days INTEGER' ))
196+ conn .commit ()
190197 migrations_applied .append ("custom_notification_days" )
191198
192199 if migrations_applied :
0 commit comments