-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $$; |