|
| 1 | +-- Past this into your Superbase SQL Editor |
| 2 | + |
| 3 | +-- Note: change this if changing the DB connection name |
| 4 | +-- connect postgres; |
| 5 | +-- Create tables |
| 6 | +CREATE TABLE public.lists( |
| 7 | + id uuid NOT NULL DEFAULT gen_random_uuid(), |
| 8 | + created_at timestamp with time zone NOT NULL DEFAULT now(), |
| 9 | + name text NOT NULL, |
| 10 | + owner_id uuid NOT NULL, |
| 11 | + CONSTRAINT lists_pkey PRIMARY KEY (id) |
| 12 | +); |
| 13 | + |
| 14 | +CREATE TABLE public.todos( |
| 15 | + id uuid NOT NULL DEFAULT gen_random_uuid(), |
| 16 | + created_at timestamp with time zone NOT NULL DEFAULT now(), |
| 17 | + completed_at timestamp with time zone NULL, |
| 18 | + description text NOT NULL, |
| 19 | + completed boolean NOT NULL DEFAULT FALSE, |
| 20 | + created_by uuid NULL, |
| 21 | + completed_by uuid NULL, |
| 22 | + list_id uuid NOT NULL, |
| 23 | + photo_id uuid NULL, |
| 24 | + CONSTRAINT todos_pkey PRIMARY KEY (id) |
| 25 | +); |
| 26 | + |
| 27 | +-- Creates some initial data to be synced |
| 28 | +INSERT INTO lists( |
| 29 | + id, |
| 30 | + name, |
| 31 | + owner_id) |
| 32 | +VALUES ( |
| 33 | + '75f89104-d95a-4f16-8309-5363f1bb377a', |
| 34 | + 'Getting Started', |
| 35 | + gen_random_uuid()); |
| 36 | + |
| 37 | +INSERT INTO todos( |
| 38 | + description, |
| 39 | + list_id, |
| 40 | + completed) |
| 41 | +VALUES ( |
| 42 | + 'Run services locally', |
| 43 | + '75f89104-d95a-4f16-8309-5363f1bb377a', |
| 44 | + TRUE); |
| 45 | + |
| 46 | +INSERT INTO todos( |
| 47 | + description, |
| 48 | + list_id, |
| 49 | + completed) |
| 50 | +VALUES ( |
| 51 | + 'Create a todo here. Query the todos table via a Postgres connection. Your todo should be synced', |
| 52 | + '75f89104-d95a-4f16-8309-5363f1bb377a', |
| 53 | + FALSE); |
| 54 | + |
| 55 | +-- Create publication for PowerSync tables |
| 56 | +CREATE PUBLICATION powersync FOR ALL TABLES; |
0 commit comments