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 13, 2024
1 parent a6cc99b commit 2813f1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ CREATE TABLE contact (
username citext, -- reference to web user
default_channel_id bigint NOT NULL REFERENCES channel(id),
color varchar(7) NOT NULL, -- hex color codes e.g #000000
external_uuid uuid NOT NULL,

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

CREATE TABLE contact_address (
Expand All @@ -74,8 +76,10 @@ CREATE TABLE contactgroup (
id bigserial,
name citext NOT NULL,
color varchar(7) NOT NULL, -- hex color codes e.g #000000
external_uuid uuid NOT NULL,

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

CREATE TABLE contactgroup_member (
Expand Down
16 changes: 16 additions & 0 deletions schema/pgsql/upgrades/029.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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;

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;

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

DROP EXTENSION "uuid-ossp";


ALTER TABLE contact DROP COLUMN external_uuid;
ALTER TABLE contactgroup DROP COLUMN external_uuid;

0 comments on commit 2813f1e

Please sign in to comment.