EliramShemesh commited on
Commit
2fdbfa6
·
verified ·
1 Parent(s): 2c3a9ec

ci: deploy backend from 46c8465ba661eac28bda36bcb74d17d69e976363

Browse files
Files changed (1) hide show
  1. database.py +11 -1
database.py CHANGED
@@ -231,7 +231,7 @@ def ensure_schema_updates():
231
 
232
  # Fix total_installments to allow NULL for standing orders
233
  # SQLite doesn't support ALTER COLUMN, so we recreate the table if needed
234
- # PostgreSQL supports ALTER COLUMN natively, so skip this for non-SQLite databases
235
  if database_url.startswith("sqlite"):
236
  with engine.begin() as connection:
237
  # Use PRAGMA to check if total_installments has NOT NULL constraint
@@ -278,6 +278,16 @@ def ensure_schema_updates():
278
 
279
  # Drop old table
280
  connection.execute(text('DROP TABLE "installmentplan_old"'))
 
 
 
 
 
 
 
 
 
 
281
 
282
 
283
 
 
231
 
232
  # Fix total_installments to allow NULL for standing orders
233
  # SQLite doesn't support ALTER COLUMN, so we recreate the table if needed
234
+ # PostgreSQL supports ALTER COLUMN natively
235
  if database_url.startswith("sqlite"):
236
  with engine.begin() as connection:
237
  # Use PRAGMA to check if total_installments has NOT NULL constraint
 
278
 
279
  # Drop old table
280
  connection.execute(text('DROP TABLE "installmentplan_old"'))
281
+ elif database_url.startswith("postgresql") or database_url.startswith("postgres"):
282
+ # PostgreSQL: use ALTER COLUMN to drop NOT NULL constraint
283
+ with engine.begin() as connection:
284
+ try:
285
+ connection.execute(text(
286
+ 'ALTER TABLE installmentplan ALTER COLUMN total_installments DROP NOT NULL'
287
+ ))
288
+ except Exception as e:
289
+ # If it fails (e.g., already nullable), just log and continue
290
+ print(f"DB init note: Could not alter total_installments column (may already be nullable): {e}")
291
 
292
 
293