|
| 1 | + |
| 2 | +-- Create the Replication publication |
| 3 | +CREATE PUBLICATION supabase_realtime FOR ALL TABLES; |
| 4 | + |
| 5 | +-- Create a second schema |
| 6 | +CREATE SCHEMA personal; |
| 7 | + |
| 8 | +-- USERS |
| 9 | +CREATE TYPE public.user_status AS ENUM ('ONLINE', 'OFFLINE'); |
| 10 | +CREATE TABLE public.users ( |
| 11 | + username text primary key, |
| 12 | + inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 13 | + updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 14 | + data jsonb DEFAULT null, |
| 15 | + age_range int4range DEFAULT null, |
| 16 | + status user_status DEFAULT 'ONLINE'::public.user_status, |
| 17 | + catchphrase tsvector DEFAULT null |
| 18 | +); |
| 19 | +ALTER TABLE public.users REPLICA IDENTITY FULL; -- Send "previous data" to supabase |
| 20 | +COMMENT ON COLUMN public.users.data IS 'For unstructured data and prototyping.'; |
| 21 | + |
| 22 | +-- CHANNELS |
| 23 | +CREATE TABLE public.channels ( |
| 24 | + id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, |
| 25 | + inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 26 | + updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 27 | + data jsonb DEFAULT null, |
| 28 | + slug text |
| 29 | +); |
| 30 | +ALTER TABLE public.users REPLICA IDENTITY FULL; -- Send "previous data" to supabase |
| 31 | +COMMENT ON COLUMN public.channels.data IS 'For unstructured data and prototyping.'; |
| 32 | + |
| 33 | +-- MESSAGES |
| 34 | +CREATE TABLE public.messages ( |
| 35 | + id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, |
| 36 | + inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 37 | + updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 38 | + data jsonb DEFAULT null, |
| 39 | + message text, |
| 40 | + username text REFERENCES users NOT NULL, |
| 41 | + channel_id bigint REFERENCES channels NOT NULL |
| 42 | +); |
| 43 | +ALTER TABLE public.messages REPLICA IDENTITY FULL; -- Send "previous data" to supabase |
| 44 | +COMMENT ON COLUMN public.messages.data IS 'For unstructured data and prototyping.'; |
| 45 | + |
| 46 | +-- STORED FUNCTION |
| 47 | +CREATE FUNCTION public.get_status(name_param text) |
| 48 | +RETURNS user_status AS $$ |
| 49 | + SELECT status from users WHERE username=name_param; |
| 50 | +$$ LANGUAGE SQL IMMUTABLE; |
| 51 | + |
| 52 | +-- SECOND SCHEMA USERS |
| 53 | +CREATE TYPE personal.user_status AS ENUM ('ONLINE', 'OFFLINE'); |
| 54 | +CREATE TABLE personal.users( |
| 55 | + username text primary key, |
| 56 | + inserted_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 57 | + updated_at timestamp without time zone DEFAULT timezone('utc'::text, now()) NOT NULL, |
| 58 | + data jsonb DEFAULT null, |
| 59 | + age_range int4range DEFAULT null, |
| 60 | + status user_status DEFAULT 'ONLINE'::public.user_status |
| 61 | +); |
| 62 | + |
| 63 | +-- SECOND SCHEMA STORED FUNCTION |
| 64 | +CREATE FUNCTION personal.get_status(name_param text) |
| 65 | +RETURNS user_status AS $$ |
| 66 | + SELECT status from users WHERE username=name_param; |
| 67 | +$$ LANGUAGE SQL IMMUTABLE; |
0 commit comments