-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-setup.sql
More file actions
98 lines (80 loc) · 3.28 KB
/
Copy pathsupabase-setup.sql
File metadata and controls
98 lines (80 loc) · 3.28 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
create table if not exists public.ritual_clicker_saves (
user_id uuid not null references auth.users(id) on delete cascade,
wallet_address text not null unique,
progress jsonb not null default '{}'::jsonb,
updated_at timestamptz not null default now()
);
grant usage on schema public to anon, authenticated;
grant select, insert, update on public.ritual_clicker_saves to authenticated;
grant select on public.ritual_clicker_saves to anon;
alter table public.ritual_clicker_saves
drop constraint if exists ritual_clicker_saves_pkey;
alter table public.ritual_clicker_saves
add constraint ritual_clicker_saves_pkey primary key (wallet_address);
create index if not exists ritual_clicker_saves_user_id_idx
on public.ritual_clicker_saves (user_id);
update public.ritual_clicker_saves
set progress = progress - 'profileAvatar'
where progress ? 'profileAvatar';
drop view if exists public.ritual_clicker_leaderboard cascade;
create view public.ritual_clicker_leaderboard
with (security_invoker = true)
as
select
wallet_address,
progress->>'playerName' as player_name,
coalesce((progress->>'totalEarned')::numeric, 0) as total_earned,
coalesce((progress->>'totalClicks')::bigint, 0) as total_clicks,
updated_at
from public.ritual_clicker_saves;
grant select on public.ritual_clicker_leaderboard to anon, authenticated;
alter table public.ritual_clicker_saves enable row level security;
drop policy if exists "Players can read own ritual save" on public.ritual_clicker_saves;
drop policy if exists "Anyone can read ritual leaderboard" on public.ritual_clicker_saves;
create policy "Anyone can read ritual leaderboard"
on public.ritual_clicker_saves
for select
to anon, authenticated
using (true);
drop policy if exists "Players can create own ritual save" on public.ritual_clicker_saves;
create policy "Players can create own ritual save"
on public.ritual_clicker_saves
for insert
to authenticated
with check (auth.uid() = user_id);
drop policy if exists "Players can update own ritual save" on public.ritual_clicker_saves;
create policy "Players can update own ritual save"
on public.ritual_clicker_saves
for update
to authenticated
using (true)
with check (auth.uid() = user_id);
create table if not exists public.ritual_daily_quests (
quest_date text primary key,
quest jsonb not null default '{}'::jsonb,
generated_by text,
tx_hash text,
updated_at timestamptz not null default now()
);
grant select, insert, update on public.ritual_daily_quests to authenticated;
grant select on public.ritual_daily_quests to anon;
alter table public.ritual_daily_quests enable row level security;
drop policy if exists "Anyone can read ritual daily quests" on public.ritual_daily_quests;
create policy "Anyone can read ritual daily quests"
on public.ritual_daily_quests
for select
to anon, authenticated
using (true);
drop policy if exists "Authenticated users can create ritual daily quests" on public.ritual_daily_quests;
create policy "Authenticated users can create ritual daily quests"
on public.ritual_daily_quests
for insert
to authenticated
with check (true);
drop policy if exists "Authenticated users can update ritual daily quests" on public.ritual_daily_quests;
create policy "Authenticated users can update ritual daily quests"
on public.ritual_daily_quests
for update
to authenticated
using (true)
with check (true);