From 4b754c9d779296709399ca09080afdfcd7400aab Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Tue, 30 Jun 2026 13:41:37 +0200 Subject: [PATCH] feat: colonnes de votes sur subscriptions #94 Co-Authored-By: Claude Sonnet 4.6 --- src/migrations.py | 8 ++++++++ src/subscriptions/db.py | 2 ++ tests/subscriptions/test_db.py | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/migrations.py b/src/migrations.py index 7603538..11061e8 100644 --- a/src/migrations.py +++ b/src/migrations.py @@ -20,6 +20,14 @@ _MIGRATIONS: list[tuple[str, str]] = [ "0002_add_siret_to_users", "ALTER TABLE users ADD COLUMN siret TEXT", ), + ( + "0003_add_votes_balance_to_subscriptions", + "ALTER TABLE subscriptions ADD COLUMN votes_balance INTEGER NOT NULL DEFAULT 0", + ), + ( + "0004_add_votes_credited_until_to_subscriptions", + "ALTER TABLE subscriptions ADD COLUMN votes_credited_until TEXT", + ), ] diff --git a/src/subscriptions/db.py b/src/subscriptions/db.py index b61458f..b032c88 100644 --- a/src/subscriptions/db.py +++ b/src/subscriptions/db.py @@ -13,6 +13,8 @@ CREATE TABLE IF NOT EXISTS subscriptions ( status TEXT, current_period_end TEXT, trial_used INTEGER NOT NULL DEFAULT 0, + votes_balance INTEGER NOT NULL DEFAULT 0, + votes_credited_until TEXT, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE diff --git a/tests/subscriptions/test_db.py b/tests/subscriptions/test_db.py index 3f9aa61..154fa55 100644 --- a/tests/subscriptions/test_db.py +++ b/tests/subscriptions/test_db.py @@ -118,3 +118,12 @@ def test_trial_used_is_sticky_across_resubscribe(users_db_path): db.update_from_webhook("decpinfo-1", "sub_42", "expired", _past()) db.create_pending(uid, "decpinfo-1", "soutien") assert db.has_used_trial(uid) is True + + +def test_init_schema_creates_votes_columns(users_db_path): + db.init_schema() + uid = _make_user() + db.create_pending(uid, "decpinfo-1", "simple") + row = db.get_by_user(uid) + assert row["votes_balance"] == 0 + assert row["votes_credited_until"] is None