mirror of
https://github.com/supabase/supabase.git
synced 2026-06-22 04:52:48 +08:00
42 lines
1.8 KiB
SQL
42 lines
1.8 KiB
SQL
|
|
-- Create the Replication publication
|
|
CREATE PUBLICATION supabase_realtime FOR ALL TABLES;
|
|
|
|
-- USERS
|
|
CREATE TYPE public.user_status AS ENUM ('ONLINE', 'OFFLINE');
|
|
CREATE TABLE public.users (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
data jsonb DEFAULT null,
|
|
username text,
|
|
status user_status DEFAULT 'ONLINE'::public.user_status
|
|
);
|
|
ALTER TABLE public.users REPLICA IDENTITY FULL; -- Send "previous data" to supabase
|
|
COMMENT ON COLUMN public.users.data IS 'For unstructured data and prototyping.';
|
|
|
|
-- CHANNELS
|
|
CREATE TABLE public.channels (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
data jsonb DEFAULT null,
|
|
slug text NOT NULL UNIQUE
|
|
);
|
|
ALTER TABLE public.users REPLICA IDENTITY FULL; -- Send "previous data" to supabase
|
|
COMMENT ON COLUMN public.channels.data IS 'For unstructured data and prototyping.';
|
|
|
|
-- MESSAGES
|
|
CREATE TABLE public.messages (
|
|
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
|
|
data jsonb DEFAULT null,
|
|
message text,
|
|
user_id bigint REFERENCES users NOT NULL,
|
|
channel_id bigint REFERENCES channels NOT NULL
|
|
);
|
|
ALTER TABLE public.messages REPLICA IDENTITY FULL; -- Send "previous data" to supabase
|
|
COMMENT ON COLUMN public.messages.data IS 'For unstructured data and prototyping.';
|
|
|