Payments Data Model

Payments Data Model An entity-relationship diagram generated by Archify. identity billing trial & promo audit parent_profile · payment-relevant columns only · Entity · identity parent_profile PK id bigint supabase_uid uuid email varchar(255) phone varchar(20) credits_balance integer is_premium_user boolean user_subscriptions · one row per parent · Entity · billing user_subscriptions PK id bigint FKUK parent_id bigint FK plan_id bigint status subscription_status current_period_start timestamptz current_period_end timestamptz auto_renew boolean is_trial boolean trial_started_at timestamptz trial_ended_at timestamptz cancel_at_period_end boolean billing_country varchar UK stripe_customer_id text UK stripe_subscription_id text stripe_checkout_session_id text stripe_price_id text UK revenuecat_original_transaction_id text revenuecat_store varchar promo_code_redeemed text FK pending_plan_id bigint pending_plan_effective_at timestamptz created_at timestamptz updated_at timestamptz payment_transactions · ledger · Entity · billing payment_transactions PK id bigint FK parent_id bigint FK subscription_id bigint amount numeric(10,2) currency varchar UK gateway varchar gateway_order_id varchar UK gateway_payment_id varchar status varchar refund_status varchar refund_reason text refunded_amount numeric(10,2) refund_reference_id varchar refunded_at timestamptz paid_at timestamptz billing_country varchar UK stripe_invoice_id text invoice_r2_object_key text invoice_stored_at timestamptz created_at timestamptz subscription_plans · catalog + store product ids · Entity · billing subscription_plans PK id bigint name varchar description text price numeric(10,2) currency varchar billing_interval varchar monthly_credits integer is_active boolean UK stripe_price_id text UK store_product_id text UK android_play_store_product_id text created_at timestamptz identity_trial_audit · one trial per email/phone · Entity · trial & promo identity_trial_audit PK id bigint UK identity_value text identity_type varchar FK parent_id bigint trial_consumed_at timestamptz promo_codes · Entity · trial & promo promo_codes PK id bigint UK code varchar credits_amount integer max_uses integer used_count integer expires_at timestamptz is_active boolean extension_days integer extension_type varchar FK created_by bigint created_at timestamptz promo_redemptions · UNIQUE(promo_id, parent_id) · Entity · trial & promo promo_redemptions PK id bigint FKUK promo_id bigint FKUK parent_id bigint redeemed_at timestamptz subscription_lifecycle_events · audit trail · Entity · audit subscription_lifecycle_events PK id bigint FK parent_id bigint FK user_subscription_id bigint event_type varchar previous_status subscription_status new_status subscription_status FK plan_id bigint FK previous_plan_id bigint billing_provider varchar UK gateway_event_id text gateway_subscription_id text amount numeric(10,2) currency varchar metadata jsonb created_at timestamptz processed_webhook_events · Stripe + RevenueCat dedupe · Entity · audit processed_webhook_events PK id text processed_at timestamptz belongs to on plan pending plan for paid by consumed by created by redeems by about for plan Legend PK Primary key FK Foreign key UK Unique key One Many Optional