Skip to content

Commit ebe647d

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

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

schema/pgsql/schema.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ 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

51-
CONSTRAINT pk_channel PRIMARY KEY (id)
52+
CONSTRAINT pk_channel PRIMARY KEY (id),
53+
UNIQUE (external_uuid)
5254
);
5355

5456
CREATE TABLE contact (
5557
id bigserial,
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

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

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

78-
CONSTRAINT pk_contactgroup PRIMARY KEY (id)
83+
CONSTRAINT pk_contactgroup PRIMARY KEY (id),
84+
UNIQUE (external_uuid)
7985
);
8086

8187
CREATE TABLE contactgroup_member (

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)