Skip to content

Commit c630f50

Browse files
Add column external_uuid to contact/contactgroup table
1 parent e6f870d commit c630f50

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

schema/pgsql/schema.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ CREATE TABLE channel (
4747
config text, -- JSON with channel-specific attributes
4848
-- for now type determines the implementation, in the future, this will need a reference to a concrete
4949
-- implementation to allow multiple implementations of a sms channel for example, probably even user-provided ones
50+
external_uuid uuid NOT NULL,
5051

52+
UNIQUE (external_uuid),
5153
CONSTRAINT pk_channel PRIMARY KEY (id)
5254
);
5355

@@ -56,9 +58,11 @@ CREATE TABLE contact (
5658
full_name citext NOT NULL,
5759
username citext, -- reference to web user
5860
default_channel_id bigint NOT NULL REFERENCES channel(id),
61+
external_uuid uuid NOT NULL,
5962

60-
CONSTRAINT pk_contact PRIMARY KEY (id),
61-
UNIQUE (username)
63+
UNIQUE (username),
64+
UNIQUE (external_uuid),
65+
CONSTRAINT pk_contact PRIMARY KEY (id)
6266
);
6367

6468
CREATE TABLE contact_address (
@@ -74,7 +78,9 @@ CREATE TABLE contact_address (
7478
CREATE TABLE contactgroup (
7579
id bigserial,
7680
name citext NOT NULL,
81+
external_uuid uuid NOT NULL,
7782

83+
UNIQUE (external_uuid),
7884
CONSTRAINT pk_contactgroup PRIMARY KEY (id)
7985
);
8086

schema/pgsql/upgrades/NAMEIT.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
2+
3+
ALTER TABLE contact ADD COLUMN external_uuid uuid UNIQUE;
4+
ALTER TABLE contactgroup ADD COLUMN external_uuid uuid UNIQUE;
5+
ALTER TABLE channel ADD COLUMN external_uuid uuid UNIQUE;
6+
7+
UPDATE contact SET external_uuid = uuid_generate_v4() WHERE external_uuid IS NULL;
8+
UPDATE contactgroup SET external_uuid = uuid_generate_v4() WHERE external_uuid IS NULL;
9+
UPDATE channel SET external_uuid = uuid_generate_v4() WHERE external_uuid IS NULL;
10+
11+
ALTER TABLE contact ALTER COLUMN external_uuid SET NOT NULL;
12+
ALTER TABLE contactgroup ALTER COLUMN external_uuid SET NOT NULL;
13+
ALTER TABLE channel ALTER COLUMN external_uuid SET NOT NULL;
14+
15+
DROP EXTENSION "uuid-ossp";

0 commit comments

Comments
 (0)