This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NotNull and NotEmpty constraint to Users.email column (#2248)
Fixes #2237
- Loading branch information
1 parent
09d3745
commit 87fdcec
Showing
4 changed files
with
31 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
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,6 @@ | ||
-- Set email = id@example.com for users whose email is '' (empty) or ' ' (any | ||
-- length of only white spaces) or NULL in database | ||
UPDATE users SET email=concat(id::TEXT, '@example.com') WHERE COALESCE(trim(email), '') = ''; | ||
|
||
ALTER TABLE users ALTER COLUMN email SET NOT NULL; | ||
ALTER TABLE users ADD CONSTRAINT email_notempty_check CHECK (trim(email) <> ''); |
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,6 @@ | ||
-- Create users with null/empty email value | ||
|
||
INSERT INTO users (full_name, email) VALUES ('Lorem1', ''); | ||
INSERT INTO users (full_name, email) VALUES ('Lorem2', ' '); | ||
INSERT INTO users (full_name, email) VALUES ('Lorem3', ' '); | ||
INSERT INTO users (full_name, email) VALUES ('Lorem4', NULL); |