From d694362365652bf98ecdcffef0bffa6b5fd0dd94 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 12 Nov 2025 18:19:49 -0500 Subject: Fix billing migration to work with SQLite ALTER TABLE limitations - Remove UNIQUE constraints from ALTER TABLE statements (SQLite doesn't support adding constraints via ALTER TABLE) - Add better logging for migration failures (debug level) - Rely on application logic to ensure uniqueness instead of DB constraint - This fixes the silent failure where stripe_customer_id and stripe_subscription_id columns weren't being added --- Biz/PodcastItLater/Core.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'Biz/PodcastItLater') diff --git a/Biz/PodcastItLater/Core.py b/Biz/PodcastItLater/Core.py index da1726c..42a4df2 100644 --- a/Biz/PodcastItLater/Core.py +++ b/Biz/PodcastItLater/Core.py @@ -560,10 +560,12 @@ class Database: # noqa: PLR0904 cursor = conn.cursor() # Add columns one by one (SQLite limitation) + # Note: SQLite ALTER TABLE doesn't support adding UNIQUE constraints + # We add them without UNIQUE and rely on application logic columns_to_add = [ ("plan_tier", "TEXT NOT NULL DEFAULT 'free'"), - ("stripe_customer_id", "TEXT UNIQUE"), - ("stripe_subscription_id", "TEXT UNIQUE"), + ("stripe_customer_id", "TEXT"), + ("stripe_subscription_id", "TEXT"), ("subscription_status", "TEXT"), ("current_period_start", "TIMESTAMP"), ("current_period_end", "TIMESTAMP"), @@ -575,8 +577,13 @@ class Database: # noqa: PLR0904 query = f"ALTER TABLE users ADD COLUMN {column_name} " cursor.execute(query + column_def) logger.info("Added column users.%s", column_name) - except sqlite3.OperationalError: # noqa: PERF203 - pass # Column already exists + except sqlite3.OperationalError as e: # noqa: PERF203 + # Column already exists, skip + logger.debug( + "Column users.%s already exists: %s", + column_name, + e, + ) conn.commit() -- cgit v1.2.3