-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
46 lines (38 loc) · 1.87 KB
/
supabase_schema.sql
File metadata and controls
46 lines (38 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- Create Favorites Table
create table public.favorites (
id bigint generated by default as identity primary key,
wallet_address text not null,
manga_id text not null,
title text,
cover_url text,
created_at timestamp with time zone default timezone('utc'::text, now()) not null,
-- Prevent duplicate favorites for the same user/manga
unique(wallet_address, manga_id)
);
-- Create Reading History Table
create table public.reading_history (
id bigint generated by default as identity primary key,
wallet_address text not null,
manga_id text not null,
chapter_id text not null,
last_page integer default 1,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
-- Ensure one history entry per manga per user
unique(wallet_address, manga_id)
);
-- Set up Row Level Security (RLS)
-- For a simple MVP, we can enable public access or restricted access.
-- Ideally, policies should restrict 'write' to the user owning the wallet_address,
-- but since we don't have Supabase Auth (email/password) integrated with the Wallet adapter
-- (we are just using the public key as an ID), standard RLS based on `auth.uid()` won't work directly
-- without a custom auth provider or signing mechanism.
-- FOR NOW (MVP): Enable public access but rely on client-side logic.
-- WARNING: This allows anyone to edit anyone's data if they know the API/Project URL.
-- A production app would need a "Sign in with Solana" flow to issue a Supabase JWT.
alter table public.favorites enable row level security;
alter table public.reading_history enable row level security;
-- Policy: Allow anonymous select/insert/update/delete for now (Simplest for Devnet MVP)
create policy "Public Access Favorites" on public.favorites
for all using (true) with check (true);
create policy "Public Access History" on public.reading_history
for all using (true) with check (true);