-- 1. Table for marketing banners
create table if not exists flowhub_banners (
id text primary key,
created_at timestamp with time zone default now(),
lang text not null,
title text not null,
description text,
link text,
image text,
mockup_type text not null
);
alter table flowhub_banners enable row level security;
create policy "Allow public read" on flowhub_banners for select using (true);
create policy "Allow public insert" on flowhub_banners for insert with check (true);
create policy "Allow public update" on flowhub_banners for update using (true);
create policy "Allow public delete" on flowhub_banners for delete using (true);
-- 2. Table for hotel demo registrations (leads)
create table if not exists flowhub_leads (
id uuid default gen_random_uuid() primary key,
created_at timestamp with time zone default now(),
name text not null,
hotel_name text not null,
email text not null,
phone text not null,
rooms integer not null,
modules text[] not null,
status text default 'pending'
);
alter table flowhub_leads enable row level security;
create policy "Allow public insert" on flowhub_leads for insert with check (true);
create policy "Allow public read" on flowhub_leads for select using (true);
-- 3. Table for proposals (ใบเสนอราคา)
create table if not exists flowhub_proposals (
id uuid default gen_random_uuid() primary key,
created_at timestamp with time zone default now(),
proposal_number text not null,
hotel_name text not null,
company_name text,
rooms integer not null,
selected_modules text[] not null,
monthly_price_per_room numeric not null,
total_monthly_price numeric not null,
billing_cycle text not null default 'monthly',
contact_name text,
contact_email text,
contact_phone text,
valid_until date,
notes text,
status text default 'draft'
);
alter table flowhub_proposals enable row level security;
create policy "Allow public read" on flowhub_proposals for select using (true);
create policy "Allow public insert" on flowhub_proposals for insert with check (true);
create policy "Allow public update" on flowhub_proposals for update using (true);
create policy "Allow public delete" on flowhub_proposals for delete using (true);
-- 4. Table for hotel subscriptions (ลิขสิทธิ์และการเรียกเก็บเงิน)
create table if not exists flowhub_subscriptions (
id uuid default gen_random_uuid() primary key,
updated_at timestamp with time zone default now(),
hotel_id text unique not null,
hotel_name text not null,
pms_status text default 'active',
pms_expires_at date,
cm_status text default 'active',
cm_expires_at date,
connect_status text default 'active',
connect_expires_at date,
stay_status text default 'active',
stay_expires_at date
);
alter table flowhub_subscriptions enable row level security;
create policy "Allow public read" on flowhub_subscriptions for select using (true);
create policy "Allow public insert" on flowhub_subscriptions for insert with check (true);
create policy "Allow public update" on flowhub_subscriptions for update using (true);
create policy "Allow public delete" on flowhub_subscriptions for delete using (true);
-- 5. Table for support tickets (แจ้งปัญหาการใช้งาน)
create table if not exists flowhub_tickets (
id uuid default gen_random_uuid() primary key,
created_at timestamp with time zone default now(),
hotel_name text not null,
problem_desc text not null,
contact_info text not null,
status text default 'open'
);
alter table flowhub_tickets enable row level security;
create policy "Allow public read" on flowhub_tickets for select using (true);
create policy "Allow public insert" on flowhub_tickets for insert with check (true);
create policy "Allow public update" on flowhub_tickets for update using (true);
create policy "Allow public delete" on flowhub_tickets for delete using (true);
-- 6. Table for SaaS POS tenants (ร้านอาหารสมาชิก POS)
create table if not exists flowhub_pos_tenants (
id text primary key,
name text not null,
tier text default 'free',
created_at timestamp with time zone default now()
);
alter table flowhub_pos_tenants enable row level security;
create policy "Allow public read" on flowhub_pos_tenants for select using (true);
create policy "Allow public insert" on flowhub_pos_tenants for insert with check (true);
create policy "Allow public update" on flowhub_pos_tenants for update using (true);
create policy "Allow public delete" on flowhub_pos_tenants for delete using (true);
-- 7. Table for SaaS POS menu (รายการอาหาร)
create table if not exists flowhub_pos_menu (
id uuid default gen_random_uuid() primary key,
tenant_id text not null,
name text not null,
price numeric not null,
image_url text,
category text not null,
in_stock boolean default true,
created_at timestamp with time zone default now()
);
alter table flowhub_pos_menu enable row level security;
create policy "Allow public read" on flowhub_pos_menu for select using (true);
create policy "Allow public insert" on flowhub_pos_menu for insert with check (true);
create policy "Allow public update" on flowhub_pos_menu for update using (true);
create policy "Allow public delete" on flowhub_pos_menu for delete using (true);
-- 8. Table for SaaS POS orders (รายการขาย)
create table if not exists flowhub_pos_orders (
id uuid default gen_random_uuid() primary key,
tenant_id text not null,
table_no text not null,
items jsonb not null,
subtotal numeric not null,
tax numeric not null,
service_charge numeric not null,
discount numeric not null,
total numeric not null,
payment_method text not null,
status text default 'pending',
created_at timestamp with time zone default now()
);
alter table flowhub_pos_orders enable row level security;
create policy "Allow public read" on flowhub_pos_orders for select using (true);
create policy "Allow public insert" on flowhub_pos_orders for insert with check (true);
create policy "Allow public update" on flowhub_pos_orders for update using (true);
create policy "Allow public delete" on flowhub_pos_orders for delete using (true);