|
| 1 | +-- TODO change this if changing the DB connection name |
| 2 | +\connect postgres; |
| 3 | + |
| 4 | +-- Create tables |
| 5 | +create table public.lists ( |
| 6 | + id uuid not null default gen_random_uuid (), |
| 7 | + created_at timestamp with time zone not null default now(), |
| 8 | + name text not null, |
| 9 | + owner_id uuid not null, |
| 10 | + constraint lists_pkey primary key (id) |
| 11 | + ); |
| 12 | + |
| 13 | +create table public.todos ( |
| 14 | + id uuid not null default gen_random_uuid (), |
| 15 | + created_at timestamp with time zone not null default now(), |
| 16 | + completed_at timestamp with time zone null, |
| 17 | + description text not null, |
| 18 | + completed boolean not null default false, |
| 19 | + created_by uuid null, |
| 20 | + completed_by uuid null, |
| 21 | + list_id uuid not null, |
| 22 | + photo_id uuid null, |
| 23 | + constraint todos_pkey primary key (id) |
| 24 | + ); |
| 25 | + |
| 26 | +CREATE TABLE checkpoints ( |
| 27 | + user_id VARCHAR(255), |
| 28 | + client_id VARCHAR(255), |
| 29 | + checkpoint INTEGER, |
| 30 | + PRIMARY KEY (user_id, client_id) |
| 31 | +); |
| 32 | + |
| 33 | +-- Creates some initial data to be synced |
| 34 | +INSERT INTO lists (id, name, owner_id) VALUES ('75f89104-d95a-4f16-8309-5363f1bb377a', 'Getting Started', gen_random_uuid() ); |
| 35 | +INSERT INTO todos(description, list_id, completed) VALUES ('Run services locally', '75f89104-d95a-4f16-8309-5363f1bb377a', true); |
| 36 | +INSERT INTO todos (description, list_id, completed) VALUES ('Create a todo here. Query the todos table via a Postgres connection. Your todo should be synced', '75f89104-d95a-4f16-8309-5363f1bb377a', false); |
| 37 | + |
| 38 | +-- Create publication for PowerSync |
| 39 | +-- Note that the `checkpoints` table is required in the publication |
| 40 | +create publication powersync for table lists, todos, checkpoints; |
0 commit comments