premium_subscriptions table
The premium_subscriptions table in the Reddit Clone Database Schema schema has 10 columns, keyed by id, with 2 foreign keys to users.
source records whether premium was bought, gifted or granted by an award, which matters because only a purchased subscription can be refunded and only a recurring one can be cancelled.
Columns (10)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| user_id | uuid | not null, references users.id | |
| plan | premium_plan | not null | |
| status | subscription_status | not null | |
| gifted_by | uuid | references users.id | |
| source | premium_source | not null | |
| started_at | timestamptz | not null | |
| current_period_end | timestamptz | ||
| cancel_at_period_end | boolean | not null | |
| canceled_at | timestamptz |
Indexes (2)
(user_id, status)(status, current_period_end)