ChandimaPrabath commited on
Commit
b2a340a
·
1 Parent(s): 07c16c1
Files changed (2) hide show
  1. init_supabase_sql.txt +8 -11
  2. main.py +2 -6
init_supabase_sql.txt CHANGED
@@ -1,19 +1,16 @@
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
- user_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(user_id),
17
  token text not null,
18
  expires timestamp with time zone not null,
19
  device text not null,
 
 
 
 
1
  -- Users table
2
+ CREATE TABLE IF NOT EXISTS public.users (
3
+ user_id varchar(16) PRIMARY KEY, -- Use BIGINT for larger integer values
4
+ username TEXT UNIQUE NOT NULL,
5
+ password TEXT NOT NULL,
6
+ email TEXT,
7
+ date_joined TIMESTAMP WITH TIME ZONE NOT NULL,
8
+ access_level TEXT NOT NULL
9
  );
10
 
11
  -- Sessions table with composite primary key (user_id, token)
12
  create table if not exists public.sessions (
13
+ user_id varchar(16) references public.users(user_id),
14
  token text not null,
15
  expires timestamp with time zone not null,
16
  device text not null,
main.py CHANGED
@@ -72,7 +72,7 @@ class UpdateUserRequest(BaseModel):
72
  class UpdateAccessLevelRequest(BaseModel):
73
  access_level: str
74
 
75
- def generate_numeric_user_id(length=10):
76
  """
77
  Generates a numeric user ID with the specified length.
78
 
@@ -93,10 +93,6 @@ def generate_numeric_user_id(length=10):
93
 
94
  return numeric_id
95
 
96
- # Generate and print a numeric user ID
97
- user_id = generate_numeric_user_id()
98
- print(f"Generated User ID: {user_id}")
99
-
100
  # Utility functions
101
  def hash_password(password: str) -> str:
102
  return hashlib.sha256(password.encode()).hexdigest()
@@ -146,7 +142,7 @@ async def signup(request: SignupRequest):
146
  )
147
 
148
  user_data = {
149
- "user_id": int(generate_numeric_user_id(length=16)),
150
  "username": request.username,
151
  "password": hash_password(request.password),
152
  "email": request.email,
 
72
  class UpdateAccessLevelRequest(BaseModel):
73
  access_level: str
74
 
75
+ def generate_numeric_user_id(length=16):
76
  """
77
  Generates a numeric user ID with the specified length.
78
 
 
93
 
94
  return numeric_id
95
 
 
 
 
 
96
  # Utility functions
97
  def hash_password(password: str) -> str:
98
  return hashlib.sha256(password.encode()).hexdigest()
 
142
  )
143
 
144
  user_data = {
145
+ "user_id": int(generate_numeric_user_id()),
146
  "username": request.username,
147
  "password": hash_password(request.password),
148
  "email": request.email,