From 2732c2e3ba50f28c4c8a3b244783bc70d04806fa Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 9 Sep 2018 13:51:54 -0700 Subject: changelog ID as a sequence As noted elsewhere, auto-increment sequences in postgres, mysql, and cockroach can have gaps: when transactions that increment a number are rolled back, a "gap" is left. I didn't realize this, and it's problematic for the external changelog API. I'll need to re-write the changelog inserter to query for the current highest number when inserting, which is unfortunate and might slow down bulk imports. --- rust/migrations/2018-05-12-001226_init/down.sql | 2 ++ rust/migrations/2018-05-12-001226_init/up.sql | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'rust') diff --git a/rust/migrations/2018-05-12-001226_init/down.sql b/rust/migrations/2018-05-12-001226_init/down.sql index 3f796db6..7667d122 100644 --- a/rust/migrations/2018-05-12-001226_init/down.sql +++ b/rust/migrations/2018-05-12-001226_init/down.sql @@ -31,3 +31,5 @@ DROP TABLE IF EXISTS abstracts CASCADE; DROP TABLE IF EXISTS editor CASCADE; DROP TABLE IF EXISTS editgroup CASCADE; DROP TABLE IF EXISTS changelog CASCADE; + +DROP SEQUENCE IF EXISTS changelog_seq CASCADE; diff --git a/rust/migrations/2018-05-12-001226_init/up.sql b/rust/migrations/2018-05-12-001226_init/up.sql index 6b0e9c6e..3ca954ca 100644 --- a/rust/migrations/2018-05-12-001226_init/up.sql +++ b/rust/migrations/2018-05-12-001226_init/up.sql @@ -30,8 +30,10 @@ ALTER TABLE editor ADD CONSTRAINT editor_editgroupid_fkey FOREIGN KEY (active_editgroup_id) REFERENCES editgroup(id); +CREATE SEQUENCE changelog_seq START 1 INCREMENT 1; + CREATE TABLE changelog ( - id BIGSERIAL PRIMARY KEY, + id BIGINT PRIMARY KEY DEFAULT nextval('changelog_seq'), editgroup_id UUID REFERENCES editgroup(id) NOT NULL, timestamp TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL ); -- cgit v1.2.3