-- ① messages 表
create table if not exists messages (
id uuid primary key default gen_random_uuid(),
sender_id text not null,
sender_name text,
sender_emoji text,
room_id text not null,
content text not null,
created_at timestamptz default now()
);
alter table messages enable row level security;
create policy "all_access" on messages
for all using (true) with check (true);
-- ② moments 表(人生轨迹 + 朋友圈)
create table if not exists moments (
id uuid primary key default gen_random_uuid(),
user_id text not null,
title text,
taken_at timestamptz default now(),
created_at timestamptz default now(),
lat double precision,
lng double precision,
photo_url text,
image_urls text,
with_people text,
is_city_level boolean default false,
mood text,
visibility text default 'all'
);
alter table moments enable row level security;
create policy "all_access" on moments
for all using (true) with check (true);
-- ③ user_locations 表(防失联)
create table if not exists user_locations (
user_id text primary key,
lat double precision,
lng double precision,
battery int,
updated_at timestamptz default now()
);
alter table user_locations enable row level security;
create policy "all_access" on user_locations
for all using (true) with check (true);
-- ④ circles 表(家庭圈)
create table if not exists circles (
id uuid primary key default gen_random_uuid(),
owner_id text not null,
member_id text,
nickname text,
status text default 'active',
invite_code text,
created_at timestamptz default now()
);
alter table circles enable row level security;
create policy "all_access" on circles
for all using (true) with check (true);
-- ⑤ 补充字段(已有表运行这个)
alter table moments add column if not exists image_urls text;
alter table moments add column if not exists photo_url text;
alter table moments add column if not exists created_at timestamptz default now();
alter table moments add column if not exists is_city_level boolean default false;
alter table moments add column if not exists with_people text;
alter table moments add column if not exists mood text;
alter table moments add column if not exists visibility text default null;
-- ⑥ profiles 表(用户资料 + 邀请码)
create table if not exists profiles (
id text primary key,
display_name text,
emoji text default '😊',
bio text,
phone text,
email text,
city text,
role text,
invite_code text,
created_at timestamptz default now()
);
alter table profiles enable row level security;
create policy "all_access" on profiles
for all using (true) with check (true);
-- ⑦ reunions 表(Reunion Moment 相遇记录)
create table if not exists reunions (
id uuid primary key default gen_random_uuid(),
user_id text not null,
member_id text not null,
met_at timestamptz default now(),
dist_meters int,
created_at timestamptz default now()
);
alter table reunions enable row level security;
create policy "all_access" on reunions
for all using (true) with check (true);
-- Storage: 创建 public bucket
-- 去 Storage → New Bucket → Name: moments → Public: ✅ ON
Supabase → SQL Editor → New query → 粘贴 → Run
完成后消息自动持久化,历史记录不丢失