ChandimaPrabath commited on
Commit
284bb72
·
1 Parent(s): 02c2293

added await to asyncio

Browse files
Files changed (2) hide show
  1. init_supabase_sql2.txt +47 -0
  2. main.py +1 -1
init_supabase_sql2.txt ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- Enable UUID extension
2
+ create extension if not exists "uuid-ossp";
3
+
4
+ -- Users table
5
+ create table if not exists public.users (
6
+ id uuid primary key,
7
+ username text unique not null,
8
+ password text not null,
9
+ email text,
10
+ date_joined timestamp with time zone not null,
11
+ access_level text not null
12
+ );
13
+
14
+ -- Sessions table with composite primary key (user_id, token)
15
+ create table if not exists public.sessions (
16
+ user_id uuid references public.users(id),
17
+ token text not null,
18
+ expires timestamp with time zone not null,
19
+ device text not null,
20
+ primary key (user_id, token) -- Composite primary key
21
+ );
22
+
23
+ -- Create indexes for better performance
24
+ create index if not exists idx_users_username on public.users(username);
25
+ create index if not exists idx_sessions_user_id on public.sessions(user_id);
26
+ create index if not exists idx_sessions_token on public.sessions(token);
27
+
28
+ -- Set up Row Level Security (RLS)
29
+ alter table public.users enable row level security;
30
+ alter table public.sessions enable row level security;
31
+
32
+ -- Create policies
33
+ create policy "Enable read access for all users"
34
+ on public.users for select
35
+ using (true);
36
+
37
+ create policy "Enable insert for authenticated users only"
38
+ on public.users for insert
39
+ with check (true);
40
+
41
+ create policy "Enable update for authenticated users"
42
+ on public.users for update
43
+ using (true);
44
+
45
+ create policy "Enable all access for sessions"
46
+ on public.sessions for all
47
+ using (true);
main.py CHANGED
@@ -416,4 +416,4 @@ app.include_router(admin_router)
416
  @app.on_event("startup")
417
  async def startup_event():
418
  await init_system_user()
419
- asyncio.create_task(clean_expired_tokens())
 
416
  @app.on_event("startup")
417
  async def startup_event():
418
  await init_system_user()
419
+ await asyncio.create_task(clean_expired_tokens())