diff --git a/sql/ion_auth.mssql.sql b/sql/ion_auth.mssql.sql index 26b404a10..38694b893 100644 --- a/sql/ion_auth.mssql.sql +++ b/sql/ion_auth.mssql.sql @@ -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), diff --git a/sql/migrating_from_ionauth2/migrate.mssql.sql b/sql/migrating_from_ionauth2/migrate.mssql.sql index 089a0b80d..97433870d 100644 --- a/sql/migrating_from_ionauth2/migrate.mssql.sql +++ b/sql/migrating_from_ionauth2/migrate.mssql.sql @@ -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