-- Stripe Checkout sessions started from the package cards. The package is -- granted once, when the payment is confirmed (webhook, or the return page -- asking Stripe), and the session id keeps that from happening twice. CREATE TABLE stripe_checkouts ( -- Stripe's Checkout Session id (cs_test_… / cs_live_…). id text PRIMARY KEY, user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE, package text NOT NULL, price_huf integer NOT NULL CHECK (price_huf > 0), live boolean NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), completed_at timestamptz, order_id uuid REFERENCES package_orders ON DELETE SET NULL ); CREATE INDEX stripe_checkouts_user_idx ON stripe_checkouts (user_id, created_at DESC);