记录我们的每一天
请问,访问者是谁?
输入正确的名字才能进入,写下的内容会记录你的名字和时间
连接后,任何一方写完记录都会立刻上传,对方打开或刷新页面就能看到,不用再导出导入。
1. 在 Supabase 建一个免费项目,进入左侧 SQL Editor,新建查询。
2. 把下面这段完整粘贴进去,点 Run 执行一次,看到 Success 即可。
3. 取项目地址:浏览器地址栏里 /project/ 后面那一串就是项目 ID,拼成 https://项目ID.supabase.co;也可以在 Settings → Data API 页面直接复制 Project URL。
4. 取密钥:Settings → API Keys 页面,复制 Publishable key(sb_publishable_ 开头);旧版界面则复制 anon public。切勿使用 sb_secret_ 或 service_role 密钥。
5. 两个值填进上面的框,点「保存并连接」,状态变绿即成功。两台设备各填一次,填同样的值。
create table if not exists love_diary ( id text primary key, type text not null, author text not null, content text not null, ts bigint not null, created_at timestamptz default now() ); alter table love_diary enable row level security; drop policy if exists diary_select on love_diary; create policy diary_select on love_diary for select to anon, authenticated using (true); drop policy if exists diary_insert on love_diary; create policy diary_insert on love_diary for insert to anon, authenticated with check (true); drop policy if exists diary_update on love_diary; create policy diary_update on love_diary for update to anon, authenticated using (true) with check (true); drop policy if exists diary_delete on love_diary; create policy diary_delete on love_diary for delete to anon, authenticated using (true);
同样在 SQL Editor 里粘贴执行一次即可。执行后「添加合照」才会真正上传到云端,对方刷新就能看到;不执行则只能本机添加。
create table if not exists love_photos (
id text primary key,
author text,
kind text not null,
path text,
ts bigint not null
);
alter table love_photos enable row level security;
drop policy if exists photos_select on love_photos;
create policy photos_select on love_photos
for select to anon, authenticated using (true);
drop policy if exists photos_insert on love_photos;
create policy photos_insert on love_photos
for insert to anon, authenticated with check (true);
drop policy if exists photos_delete on love_photos;
create policy photos_delete on love_photos
for delete to anon, authenticated using (true);
insert into storage.buckets (id, name, public)
values ('love-photos', 'love-photos', true)
on conflict (id) do nothing;
drop policy if exists photos_file_read on storage.objects;
create policy photos_file_read on storage.objects
for select to anon, authenticated using (bucket_id = 'love-photos');
drop policy if exists photos_file_write on storage.objects;
create policy photos_file_write on storage.objects
for insert to anon, authenticated with check (bucket_id = 'love-photos');
drop policy if exists photos_file_del on storage.objects;
create policy photos_file_del on storage.objects
for delete to anon, authenticated using (bucket_id = 'love-photos');