Skip to content

Commit 80a6186

Browse files
committed
pgsql: Conform to current schema definition
1 parent 8f8e51c commit 80a6186

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

schema/pgsql/schema.sql

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,35 @@ CREATE TABLE available_channel_type (
4242

4343
CREATE 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

6060
CREATE INDEX idx_channel_changed_at ON channel(changed_at);
6161

6262
CREATE 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

10099
CREATE 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

112111
CREATE INDEX idx_contactgroup_changed_at ON contactgroup(changed_at);

schema/pgsql/upgrades/NAMEIT.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
22

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;
3+
ALTER TABLE contact ADD COLUMN external_uuid uuid CONSTRAINT uk_contact_external_uuid UNIQUE;
4+
ALTER TABLE contactgroup ADD COLUMN external_uuid uuid CONSTRAINT uk_contactgroup_external_uuid UNIQUE;
5+
ALTER TABLE channel ADD COLUMN external_uuid uuid CONSTRAINT uk_channel_external_uuid UNIQUE;
66

77
UPDATE contact SET external_uuid = uuid_generate_v4() WHERE external_uuid IS NULL;
88
UPDATE contactgroup SET external_uuid = uuid_generate_v4() WHERE external_uuid IS NULL;

0 commit comments

Comments
 (0)