diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-12 18:19:49 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-12 18:19:49 -0500 |
| commit | d694362365652bf98ecdcffef0bffa6b5fd0dd94 (patch) | |
| tree | ec15d40e7b9cc4ede6a2b3b700aa7bd501369acc /Biz/PodcastItLater | |
| parent | 14fdc4b98a9f442df72fb8ff445f4e7f7a24a10e (diff) | |
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
Diffstat (limited to 'Biz/PodcastItLater')
| -rw-r--r-- | Biz/PodcastItLater/Core.py | 15 |
1 files changed, 11 insertions, 4 deletions
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() |
