Skip to content

Commit

Permalink
added invitation hash migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kloV148 committed Dec 5, 2023
1 parent f2331c6 commit 87fcd49
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions migrations/tenant/[email protected]
Original file line number Diff line number Diff line change
@@ -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 $$;

0 comments on commit 87fcd49

Please sign in to comment.