From 87fcd493ef6dae44e8ec127c567936b68b5bc5c1 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 5 Dec 2023 19:19:40 +0300 Subject: [PATCH] added invitation hash migration --- ...0012-note-settings@add-invitation-hash.sql | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 migrations/tenant/0012-note-settings@add-invitation-hash.sql diff --git a/migrations/tenant/0012-note-settings@add-invitation-hash.sql b/migrations/tenant/0012-note-settings@add-invitation-hash.sql new file mode 100644 index 00000000..32b7b39e --- /dev/null +++ b/migrations/tenant/0012-note-settings@add-invitation-hash.sql @@ -0,0 +1,24 @@ +-- Create "invitation hash" column in note_settings table +DO $$ +BEGIN + IF NOT EXISTS(SELECT * + FROM information_schema.columns + WHERE table_name='note_settings' and column_name='invitation_hash') + THEN + ALTER TABLE "public"."note_settings" ADD COLUMN "invitation_hash" VARCHAR(255); + END IF; +END $$; + +-- Generate invitation hash for records with NULL invitation_hash +DO $$ +BEGIN + UPDATE "public"."note_settings" + SET "invitation_hash" = SUBSTRING(CAST(GEN_RANDOM_UUID() AS VARCHAR), 1, 10) + WHERE "invitation_hash" IS NULL; +END $$; + +-- Makes the column 'invitation_hash' NOT NULL +DO $$ +BEGIN + ALTER TABLE "public"."note_settings" ALTER COLUMN "invitation_hash" SET NOT NULL; +END $$;