Ecto schema for an account's subscription to a plan.
Subscriptions are append-friendly records. When a subscription ends, its
status transitions to "canceled" and the record remains in the database.
When an account subscribes again, HawkEx creates a new subscription record.
This preserves billing history without soft-delete semantics.
Status lifecycle
trialing ──► active ──► past_due ──► canceled
│ ▲
└──────────────────────────────┘Active statuses
Both "trialing" and "active" grant entitlement access. Use
active_statuses/0 when building queries instead of duplicating the list.
One active subscription per account
Enforced by a partial unique index on account_id where
status is in active_statuses/0. The HawkEx.Billing context also checks
this before inserting a subscription so callers receive a clear error tuple.
Summary
Functions
Statuses that grant entitlement access.
Builds a changeset for creating or updating a subscription.
All lifecycle statuses accepted by the schema.
Functions
Statuses that grant entitlement access.
Builds a changeset for creating or updating a subscription.
The schema defaults status to "active". Context functions such as
HawkEx.Billing.subscribe/2 set trial and billing period fields for normal
subscription creation.
All lifecycle statuses accepted by the schema.