Skip to content

Commit

Permalink
Fix TSQL syntax for UNIQUE constraint that can be NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Indigo744 committed Oct 13, 2018
1 parent d8b088a commit 6214bd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
15 changes: 12 additions & 3 deletions sql/ion_auth.mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ CREATE TABLE users (
phone varchar(20),
PRIMARY KEY(id),
CONSTRAINT uc_email UNIQUE (email),
CONSTRAINT uc_activation_selector UNIQUE (activation_selector),
CONSTRAINT uc_forgotten_password_selector UNIQUE (forgotten_password_selector),
CONSTRAINT uc_remember_selector UNIQUE (remember_selector),
CONSTRAINT users_check_id CHECK(id >= 0),
CONSTRAINT users_check_active CHECK(active >= 0)
);

/* Create index on col that can by NULL */
CREATE UNIQUE INDEX uc_activation_selector
ON users (activation_selector)
WHERE activation_selector IS NOT NULL

CREATE UNIQUE INDEX uc_remember_selector
ON users (remember_selector)
WHERE remember_selector IS NOT NULL

CREATE UNIQUE INDEX uc_forgotten_password_selector
ON users (forgotten_password_selector)
WHERE forgotten_password_selector IS NOT NULL

CREATE TABLE groups (
id int NOT NULL IDENTITY(1,1),
Expand Down
22 changes: 11 additions & 11 deletions sql/migrating_from_ionauth2/migrate.mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ ALTER TABLE users
ADD CONSTRAINT uc_email
UNIQUE (email);

ALTER TABLE users
ADD CONSTRAINT uc_activation_selector
UNIQUE (activation_selector);

ALTER TABLE users
ADD CONSTRAINT uc_remember_selector
UNIQUE (remember_selector);

ALTER TABLE users
ADD CONSTRAINT uc_forgotten_password_selector
UNIQUE (forgotten_password_selector);
CREATE UNIQUE INDEX uc_activation_selector
ON users (activation_selector)
WHERE activation_selector IS NOT NULL
CREATE UNIQUE INDEX uc_remember_selector
ON users (remember_selector)
WHERE remember_selector IS NOT NULL
CREATE UNIQUE INDEX uc_forgotten_password_selector
ON users (forgotten_password_selector)
WHERE forgotten_password_selector IS NOT NULL

0 comments on commit 6214bd2

Please sign in to comment.