From b997f95e96c779e967d8e8a77f5917ed89f72d97 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 11 Jun 2024 10:27:47 +0200 Subject: [PATCH] Add column `external_uuid` to `contact/contactgroup` table --- schema/pgsql/schema.sql | 2 ++ schema/pgsql/upgrades/027.sql | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 schema/pgsql/upgrades/027.sql diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 9b7ffca3b..d56062ffa 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -55,6 +55,7 @@ CREATE TABLE contact ( username text, -- 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) @@ -74,6 +75,7 @@ CREATE TABLE contactgroup ( id bigserial, name text NOT NULL, color varchar(7) NOT NULL, -- hex color codes e.g #000000 + external_uuid uuid NOT NULL, CONSTRAINT pk_contactgroup PRIMARY KEY (id) ); diff --git a/schema/pgsql/upgrades/027.sql b/schema/pgsql/upgrades/027.sql new file mode 100644 index 000000000..fcc5024ce --- /dev/null +++ b/schema/pgsql/upgrades/027.sql @@ -0,0 +1,12 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +ALTER TABLE contact ADD COLUMN external_uuid uuid; +ALTER TABLE contactgroup ADD COLUMN external_uuid uuid; + +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";