Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column external_uuid to contact/contactgroup table #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ 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,

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

CREATE TABLE contact (
id bigserial,
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)
);

CREATE TABLE contact_address (
Expand All @@ -74,8 +78,10 @@ CREATE TABLE contact_address (
CREATE TABLE contactgroup (
id bigserial,
name citext NOT NULL,
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
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";
Loading