@@ -42,36 +42,35 @@ CREATE TABLE available_channel_type (
4242
4343CREATE TABLE channel (
4444 id bigserial ,
45+ external_uuid uuid NOT NULL , -- used for external references
4546 name citext NOT NULL ,
4647 type varchar (255 ) NOT NULL , -- 'email', 'sms', ...
4748 config text , -- JSON with channel-specific attributes
4849 -- for now type determines the implementation, in the future, this will need a reference to a concrete
4950 -- implementation to allow multiple implementations of a sms channel for example, probably even user-provided ones
50- external_uuid uuid NOT NULL ,
5151
5252 changed_at bigint NOT NULL ,
5353 deleted boolenum NOT NULL DEFAULT ' n' ,
5454
5555 CONSTRAINT pk_channel PRIMARY KEY (id),
56- CONSTRAINT fk_channel_available_channel_type FOREIGN KEY (type) REFERENCES available_channel_type(type ),
57- UNIQUE (external_uuid )
56+ CONSTRAINT uk_channel_external_uuid UNIQUE (external_uuid ),
57+ CONSTRAINT fk_channel_available_channel_type FOREIGN KEY (type) REFERENCES available_channel_type(type )
5858);
5959
6060CREATE INDEX idx_channel_changed_at ON channel(changed_at);
6161
6262CREATE TABLE contact (
6363 id bigserial ,
64+ external_uuid uuid NOT NULL , -- used for external references
6465 full_name citext NOT NULL ,
6566 username citext, -- reference to web user
6667 default_channel_id bigint NOT NULL ,
67- external_uuid uuid NOT NULL ,
6868
6969 changed_at bigint NOT NULL ,
7070 deleted boolenum NOT NULL DEFAULT ' n' ,
7171
7272 CONSTRAINT pk_contact PRIMARY KEY (id),
73- UNIQUE (username),
74- UNIQUE (external_uuid),
73+ CONSTRAINT uk_contact_external_uuid UNIQUE (external_uuid),
7574
7675 -- As the username is unique, it must be NULLed for deletion via "deleted = 'y'"
7776 CONSTRAINT uk_contact_username UNIQUE (username),
@@ -99,14 +98,14 @@ CREATE INDEX idx_contact_address_changed_at ON contact_address(changed_at);
9998
10099CREATE TABLE contactgroup (
101100 id bigserial ,
101+ external_uuid uuid NOT NULL , -- used for external references
102102 name citext NOT NULL ,
103- external_uuid uuid NOT NULL ,
104103
105104 changed_at bigint NOT NULL ,
106105 deleted boolenum NOT NULL DEFAULT ' n' ,
107106
108107 CONSTRAINT pk_contactgroup PRIMARY KEY (id),
109- UNIQUE (external_uuid)
108+ CONSTRAINT uk_contactgroup_external_uuid UNIQUE (external_uuid)
110109);
111110
112111CREATE INDEX idx_contactgroup_changed_at ON contactgroup(changed_at);
0 commit comments