Last step - Create your database tables
-- Create Products Table
CREATE TABLE IF NOT EXISTS public.products (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
description TEXT,
product_type TEXT NOT NULL,
features JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.products ENABLE ROW LEVEL SECURITY;
CREATE POLICY "products_all" ON public.products FOR ALL USING (true);
INSERT INTO public.products (name, description, product_type) VALUES
('Starter Plan', 'Basic forex trading - 1:1 leverage, 1 account, 20 pairs', 'forex'),
('Professional Plan', 'Professional trading - 1:100 leverage, 3 accounts, 80 pairs', 'forex'),
('Premium Plan', 'Premium trading - 1:500 leverage, 5 accounts, 150 pairs', 'forex')
ON CONFLICT DO NOTHING;
-- Create Clients Table
CREATE TABLE IF NOT EXISTS public.clients (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
company TEXT NOT NULL,
email TEXT NOT NULL,
phone TEXT,
whatsapp_number TEXT,
telegram_id TEXT,
product_id UUID REFERENCES public.products(id),
custom_pricing DECIMAL(10,2),
billing_day INTEGER DEFAULT 1,
status TEXT DEFAULT 'active',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.clients ENABLE ROW LEVEL SECURITY;
CREATE POLICY "clients_all" ON public.clients FOR ALL USING (true);
-- Create Invoices Table
CREATE TABLE IF NOT EXISTS public.invoices (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
invoice_number TEXT NOT NULL UNIQUE,
client_id UUID NOT NULL REFERENCES public.clients(id),
billing_cycle_id UUID,
amount DECIMAL(10,2) NOT NULL,
currency TEXT DEFAULT 'USD',
due_date DATE NOT NULL,
status TEXT DEFAULT 'sent',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY "invoices_all" ON public.invoices FOR ALL USING (true);
-- Create Payments Table
CREATE TABLE IF NOT EXISTS public.payments (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
invoice_id UUID NOT NULL REFERENCES public.invoices(id),
amount DECIMAL(10,2) NOT NULL,
payment_date DATE NOT NULL,
payment_method TEXT,
reference TEXT,
notes TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.payments ENABLE ROW LEVEL SECURITY;
CREATE POLICY "payments_all" ON public.payments FOR ALL USING (true);
-- Create Reminders Table
CREATE TABLE IF NOT EXISTS public.reminders (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
invoice_id UUID NOT NULL REFERENCES public.invoices(id),
client_id UUID NOT NULL REFERENCES public.clients(id),
reminder_type TEXT,
sent_date DATE,
channels TEXT[],
status TEXT DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.reminders ENABLE ROW LEVEL SECURITY;
CREATE POLICY "reminders_all" ON public.reminders FOR ALL USING (true);Already ran the SQL? Then your database is ready! You can now: