-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add avatar_url contraint and default
- Loading branch information
1 parent
9dc82e6
commit aaef430
Showing
9 changed files
with
58 additions
and
25 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
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
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
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
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 @@ | ||
-- --- !Ups | ||
-- Update any existing null avatar_url values to the default | ||
UPDATE users | ||
SET avatar_url = '/assets/images/user_no_image.png' | ||
WHERE avatar_url IS NULL; | ||
|
||
-- Alter the table to set avatar_url as NOT NULL with a default value | ||
ALTER TABLE IF EXISTS users | ||
ALTER COLUMN avatar_url SET DEFAULT '/assets/images/user_no_image.png', | ||
ALTER COLUMN avatar_url SET NOT NULL; | ||
|
||
-- Add a CHECK constraint to ensure avatar_url is not empty | ||
ALTER TABLE IF EXISTS users | ||
ADD CONSTRAINT check_avatar_url_not_empty CHECK (avatar_url <> ''); | ||
|
||
-- --- !Downs | ||
-- Remove the CHECK constraint | ||
ALTER TABLE IF EXISTS users | ||
DROP CONSTRAINT IF EXISTS check_avatar_url_not_empty; | ||
|
||
-- Revert the avatar_url column to allow null values and remove the default value | ||
ALTER TABLE IF EXISTS users | ||
ALTER COLUMN avatar_url DROP NOT NULL, | ||
ALTER COLUMN avatar_url DROP DEFAULT; |
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
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
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
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