Skip to content

Commit 3abe1a0

Browse files
committed
add index for ops version. dont create table if existed.
1 parent 202ea6a commit 3abe1a0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

structure.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
CREATE TABLE ops (
1+
CREATE TABLE IF NOT EXISTS ops (
22
collection character varying(255) not null,
33
doc_id character varying(255) not null,
44
version integer not null,
55
operation jsonb not null, -- {v:0, create:{...}} or {v:n, op:[...]}
66
PRIMARY KEY (collection, doc_id, version)
77
);
88

9-
CREATE TABLE snapshots (
9+
CREATE TABLE IF NOT EXISTS snapshots (
1010
collection character varying(255) not null,
1111
doc_id character varying(255) not null,
1212
doc_type character varying(255) not null,
1313
version integer not null,
1414
data jsonb not null,
1515
PRIMARY KEY (collection, doc_id)
1616
);
17+
18+
CREATE INDEX IF NOT EXISTS ops_version ON snapshots (collection, doc_id, version);
19+
20+
ALTER TABLE ops
21+
ALTER COLUMN operation
22+
SET DATA TYPE jsonb
23+
USING operation::jsonb;
24+
25+
ALTER TABLE snapshots
26+
ALTER COLUMN data
27+
SET DATA TYPE jsonb
28+
USING data::jsonb;

0 commit comments

Comments
 (0)