Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit stripe schema #152

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 4 additions & 42 deletions web/db/20241110150742_add_stripe.sql
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
-- Minimal Users table
-- Users table
CREATE TABLE public.users (
id UUID REFERENCES auth.users(id) PRIMARY KEY,
full_name TEXT,
avatar_url TEXT
avatar_url TEXT,
stripe_customer_id TEXT,
pro BOOLEAN DEFAULT FALSE
);
ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Can view own data" ON public.users FOR SELECT USING (auth.uid() = id);
CREATE POLICY "Can update own data" ON public.users FOR UPDATE USING (auth.uid() = id);

-- Customers table for Stripe customer ID
CREATE TABLE public.customers (
id UUID REFERENCES auth.users(id) PRIMARY KEY,
stripe_customer_id TEXT
);

-- Minimal Products table
CREATE TABLE public.products (
id TEXT PRIMARY KEY,
active BOOLEAN,
name TEXT
);
ALTER TABLE public.products ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Allow public read-only access" ON public.products FOR SELECT USING (TRUE);

-- Minimal Prices table
CREATE TABLE public.prices (
id TEXT PRIMARY KEY,
product_id TEXT REFERENCES public.products,
active BOOLEAN,
unit_amount BIGINT,
currency TEXT CHECK (char_length(currency) = 3)
);
ALTER TABLE public.prices ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Allow public read-only access" ON public.prices FOR SELECT USING (TRUE);

-- Minimal Subscriptions table
CREATE TABLE public.subscriptions (
id TEXT PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) NOT NULL,
status TEXT,
price_id TEXT REFERENCES public.prices
);
ALTER TABLE public.subscriptions ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Can view own subs data" ON public.subscriptions FOR SELECT USING (auth.uid() = user_id);

-- Minimal real-time publication for products and prices
-- DROP PUBLICATION IF EXISTS supabase_realtime;
-- CREATE PUBLICATION supabase_realtime FOR TABLE public.products, public.prices;