-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstructure.sql
42 lines (33 loc) · 968 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
-- v5.0.0 --
ALTER TABLE snapshots
ALTER column doc_type
DROP NOT NULL;
ALTER TABLE snapshots
ALTER column data
DROP NOT NULL;
ALTER TABLE snapshots
ADD metadata jsonb;