Skip to content

Commit

Permalink
Add column external_uuid to contact/contactgroup table
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jun 27, 2024
1 parent e6f870d commit c630f50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ CREATE TABLE channel (
config text, -- JSON with channel-specific attributes
-- for now type determines the implementation, in the future, this will need a reference to a concrete
-- implementation to allow multiple implementations of a sms channel for example, probably even user-provided ones
external_uuid uuid NOT NULL,

UNIQUE (external_uuid),
CONSTRAINT pk_channel PRIMARY KEY (id)
);

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

CONSTRAINT pk_contact PRIMARY KEY (id),
UNIQUE (username)
UNIQUE (username),
UNIQUE (external_uuid),
CONSTRAINT pk_contact PRIMARY KEY (id)
);

CREATE TABLE contact_address (
Expand All @@ -74,7 +78,9 @@ CREATE TABLE contact_address (
CREATE TABLE contactgroup (
id bigserial,
name citext NOT NULL,
external_uuid uuid NOT NULL,

UNIQUE (external_uuid),
CONSTRAINT pk_contactgroup PRIMARY KEY (id)
);

Expand Down
15 changes: 15 additions & 0 deletions schema/pgsql/upgrades/NAMEIT.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

ALTER TABLE contact ADD COLUMN external_uuid uuid UNIQUE;
ALTER TABLE contactgroup ADD COLUMN external_uuid uuid UNIQUE;
ALTER TABLE channel ADD COLUMN external_uuid uuid UNIQUE;

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

ALTER TABLE contact ALTER COLUMN external_uuid SET NOT NULL;
ALTER TABLE contactgroup ALTER COLUMN external_uuid SET NOT NULL;
ALTER TABLE channel ALTER COLUMN external_uuid SET NOT NULL;

DROP EXTENSION "uuid-ossp";

0 comments on commit c630f50

Please sign in to comment.