forked from billwashere/sharedb-postgres-jsonb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstructure.sql
28 lines (24 loc) · 784 Bytes
/
structure.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
CREATE TABLE IF NOT EXISTS ops (
collection character varying(255) not null,
doc_id character varying(255) not null,
version integer not null,
operation jsonb not null, -- {v:0, create:{...}} or {v:n, op:[...]}
PRIMARY KEY (collection, doc_id, version)
);
CREATE TABLE IF NOT EXISTS snapshots (
collection character varying(255) not null,
doc_id character varying(255) not null,
doc_type character varying(255) not null,
version integer not null,
data jsonb not null,
PRIMARY KEY (collection, doc_id)
);
CREATE INDEX IF NOT EXISTS snapshots_version ON snapshots (collection, doc_id);
ALTER TABLE ops
ALTER COLUMN operation
SET DATA TYPE jsonb
USING operation::jsonb;
ALTER TABLE snapshots
ALTER COLUMN data
SET DATA TYPE jsonb
USING data::jsonb;