init commit,

This commit is contained in:
louiscklaw
2025-05-28 09:55:51 +08:00
commit efe70ceb69
8042 changed files with 951668 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
--
-- clear storage buckets
--
BEGIN;
TRUNCATE storage.buckets CASCADE;
COMMIT;
BEGIN;
CREATE TABLE employees(
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name text,
email text,
created_at timestamptz DEFAULT now()
);
ALTER TABLE IF EXISTS public.employees
ADD department text DEFAULT 'Hooli';
COMMIT;

View File

@@ -0,0 +1,24 @@
-- Create a table called "todos"
-- with a column to store tasks.
BEGIN;
DROP TABLE IF EXISTS "todos";
CREATE TABLE todos(
id serial PRIMARY KEY,
task text
);
-- Turn on security
ALTER TABLE "todos" ENABLE ROW LEVEL SECURITY;
-- Allow anonymous access
CREATE POLICY "Allow public access" ON todos
FOR SELECT TO anon
USING (TRUE);
-- Turn on security
ALTER TABLE "todos" ENABLE ROW LEVEL SECURITY;
-- Add some data
INSERT INTO todos(task)
VALUES ('Create tables'),
('Enable security'),
('Add data'),
('Fetch data from the API');
COMMIT;

View File

@@ -0,0 +1,32 @@
--
-- REQXXX countries
--
-- https://supabase.com/docs/guides/getting-started/quickstarts/reactjs
--
-- Create the table
BEGIN;
DROP TABLE IF EXISTS "countries";
CREATE TABLE countries(
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name text NOT NULL
);
-- Insert some sample data into the table
INSERT INTO countries(name)
VALUES ('Canada'),
('United States'),
('Mexico');
ALTER TABLE countries ENABLE ROW LEVEL SECURITY;
CREATE POLICY "public can read countries" ON public.countries
FOR SELECT TO anon
USING (TRUE);
CREATE POLICY "public can write countries" ON "public"."countries" AS PERMISSIVE
FOR INSERT TO public
WITH CHECK (TRUE);
CREATE POLICY "public can update countries" ON "public"."countries" AS PERMISSIVE
FOR UPDATE TO public
USING (TRUE);
CREATE POLICY "public can delete countries" ON "public"."countries" AS PERMISSIVE
FOR DELETE TO public
USING (TRUE);
COMMIT;

View File

@@ -0,0 +1,37 @@
--
-- REQXXX realtime-helloworld
--
-- https://supabase.com/docs/guides/realtime
--
-- with a column to store tasks.
BEGIN;
DROP TABLE IF EXISTS "todos_realtime";
CREATE TABLE todos_realtime(
id serial PRIMARY KEY,
task text
);
-- Add some data
INSERT INTO todos_realtime(task)
VALUES ('Create tables'),
('Enable security'),
('Add data'),
('Fetch data from the API');
ALTER publication supabase_realtime
ADD TABLE todos_realtime;
-- -- Turn on security
ALTER TABLE "todos_realtime" ENABLE ROW LEVEL SECURITY;
-- Allow anonymous access
CREATE POLICY "public can read todos_realtime" ON public.todos_realtime
FOR SELECT TO anon
USING (TRUE);
CREATE POLICY "public can write todos_realtime" ON "public"."todos_realtime" AS PERMISSIVE
FOR INSERT TO public
WITH CHECK (TRUE);
CREATE POLICY "public can update todos_realtime" ON "public"."todos_realtime" AS PERMISSIVE
FOR UPDATE TO public
USING (TRUE);
CREATE POLICY "public can delete todos_realtime" ON "public"."todos_realtime" AS PERMISSIVE
FOR DELETE TO public
USING (TRUE);
COMMIT;

View File

@@ -0,0 +1,15 @@
--
-- REQXXX test-table
--
-- https://supabase.com/docs/guides/realtime
--
BEGIN;
DROP TABLE IF EXISTS "public"."Test Table";
CREATE TABLE "public"."Test Table"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, "created_at" timestamp with time zone DEFAULT now()
);
ALTER TABLE "public"."Test Table" ENABLE ROW LEVEL SECURITY;
CREATE UNIQUE INDEX "Test Table_pkey" ON public. "Test Table" USING btree(id);
ALTER TABLE "public"."Test Table"
ADD CONSTRAINT "Test Table_pkey" PRIMARY KEY USING INDEX "Test Table_pkey";
COMMIT;

View File

@@ -0,0 +1,60 @@
--
-- original from repository
--
BEGIN;
CREATE TABLE profiles(
id uuid REFERENCES auth.users NOT NULL,
updated_at timestamp with time zone,
username text UNIQUE,
full_name text,
avatar_url text,
website text,
PRIMARY KEY (id),
UNIQUE (username),
CONSTRAINT username_length CHECK (char_length(username) >= 3)
);
COMMIT;
-- Set up Row Level Security (RLS)
-- See https://supabase.com/docs/guides/auth/row-level-security for more details.
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Public profiles are viewable by the owner." ON profiles
FOR SELECT
USING (TRUE);
CREATE POLICY "Users can insert their own profile." ON profiles
FOR INSERT
WITH CHECK (auth.uid() = id);
CREATE POLICY "Users can update own profile." ON profiles
FOR UPDATE
USING (auth.uid() = id);
-- Set up Realtime
BEGIN;
DROP publication IF EXISTS supabase_realtime;
CREATE publication supabase_realtime;
COMMIT;
ALTER publication supabase_realtime
ADD TABLE profiles;
-- Set up Storage
BEGIN;
INSERT INTO storage.buckets(id, name)
VALUES ('avatars', 'avatars');
COMMIT;
CREATE POLICY "Avatar images are publicly accessible." ON storage.objects
FOR SELECT
USING (bucket_id = 'avatars');
CREATE POLICY "Anyone can upload an avatar." ON storage.objects
FOR INSERT
WITH CHECK (bucket_id = 'avatars');
CREATE POLICY "Anyone can update an avatar." ON storage.objects
FOR UPDATE
USING (bucket_id = 'avatars');

View File

@@ -0,0 +1,41 @@
-- 007_user.sql
-- create test users
BEGIN;
INSERT INTO auth.users(instance_id, id, aud, ROLE, email, encrypted_password, email_confirmed_at, recovery_sent_at, last_sign_in_at, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, confirmation_token, email_change, email_change_token_new, recovery_token)(
SELECT
'00000000-0000-0000-0000-000000000000',
uuid_generate_v4(),
'authenticated',
'authenticated',
'user' ||(ROW_NUMBER() OVER ()) || '@example.com',
crypt('Aa1234567', gen_salt('bf')),
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'{"provider":"email","providers":["email"]}',
'{}',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'',
'',
'',
''
FROM generate_series(1, 5));
COMMIT;
-- test user email identities
BEGIN;
INSERT INTO auth.identities(id, user_id, provider_id, identity_data, provider, last_sign_in_at, created_at, updated_at)(
SELECT
uuid_generate_v4(),
id,
id,
format('{"sub":"%s","email":"%s"}', id::text, email)::jsonb,
'email',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
FROM
auth.users);
COMMIT;

View File

@@ -0,0 +1,19 @@
-- 008_store_helloworld.sql
BEGIN;
--
INSERT INTO storage.buckets(id, name)
VALUES ('store_helloworld', 'store_helloworld');
--
--
CREATE POLICY "store_helloworld Publicly accessible." ON storage.objects
FOR SELECT
USING (bucket_id = 'store_helloworld');
CREATE POLICY "store_helloworld Anyone can upload" ON storage.objects
FOR INSERT
WITH CHECK (bucket_id = 'store_helloworld');
CREATE POLICY "store_helloworld Anyone can update" ON storage.objects
FOR UPDATE
USING (bucket_id = 'store_helloworld');
--
COMMIT;

View File

@@ -0,0 +1,90 @@
-- 010_messages.sql
-- REQ0050/chat-room-list
--
BEGIN;
--
-- Create User Table
CREATE TABLE Users(
UserID serial PRIMARY KEY,
PhoneNumber varchar(255) NOT NULL,
Username varchar(255) NOT NULL,
ProfilePicture varchar(255),
Status text,
LastSeen timestamp
);
--
-- Create Contact Table
CREATE TABLE Contacts(
ContactID serial PRIMARY KEY,
UserID int NOT NULL,
ContactUserID int NOT NULL,
Nickname varchar(255),
Blocked boolean,
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (ContactUserID) REFERENCES Users(UserID)
);
--
-- Create Group Table
CREATE TABLE GROUPS (
GroupID serial PRIMARY KEY,
GroupName varchar(255),
GroupPicture varchar(255),
AdminID int NOT NULL,
CreationDate timestamp DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (AdminID) REFERENCES Users(UserID)
);
-- Create GroupMember Table
CREATE TABLE GroupMembers(
GroupMemberID serial PRIMARY KEY,
GroupID int NOT NULL,
UserID int NOT NULL,
JoinDate timestamp DEFAULT CURRENT_TIMESTAMP,
Role VARCHAR(255),
FOREIGN KEY (GroupID) REFERENCES GROUPS (GroupID),
FOREIGN KEY (UserID) REFERENCES Users(UserID)
);
CREATE TABLE public.messages(
MessageID serial PRIMARY KEY,
Content text,
created_at timestamp DEFAULT CURRENT_TIMESTAMP,
MediaURL varchar(255),
Status varchar(255),
--
-- SenderID int NOT NULL,
-- FOREIGN KEY (SenderID) REFERENCES Users(UserID),
SenderID uuid NOT NULL,
FOREIGN KEY (SenderID) REFERENCES auth.users,
-- ReceiverID int NOT NULL,
-- FOREIGN KEY (ReceiverID) REFERENCES Users(UserID)
ReceiverID uuid NOT NULL,
FOREIGN KEY (ReceiverID) REFERENCES auth.users
);
-- -- Turn on security
ALTER TABLE public.messages ENABLE ROW LEVEL SECURITY;
--
ALTER publication supabase_realtime
ADD TABLE public.messages;
--
CREATE POLICY "public can read public.messages" ON public.messages
FOR SELECT TO anon
USING (TRUE);
CREATE POLICY "public can write public.messages" ON public.messages AS PERMISSIVE
FOR INSERT TO public
WITH CHECK (TRUE);
CREATE POLICY "public can update public.messages" ON public.messages AS PERMISSIVE
FOR UPDATE TO public
USING (TRUE);
CREATE POLICY "public can delete public.messages" ON public.messages AS PERMISSIVE
FOR DELETE TO public
USING (TRUE);
--
INSERT INTO public.messages(MessageID, Content, created_at, MediaURL, Status, SenderID, ReceiverID) (
SELECT
ROW_NUMBER() OVER ()::integer, 'hello message', CURRENT_TIMESTAMP, '/google.png', 'sent',
( SELECT id FROM auth.users WHERE email = 'user1@example.com'),
( SELECT id FROM auth.users WHERE email = 'user2@example.com')
FROM generate_series(1, 5)
);
COMMIT;
-- 'user' ||(ROW_NUMBER() OVER ()) || '@example.com'