mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
41 lines
1.1 KiB
SQL
41 lines
1.1 KiB
SQL
CREATE TABLE Auth.UserCredential -- delete credentials when user account is deleted
|
|
(
|
|
UserCredentialID UNIQUEIDENTIFIER
|
|
CONSTRAINT DF_UserCredentialID DEFAULT NEWID(),
|
|
|
|
UserAccountID UNIQUEIDENTIFIER NOT NULL,
|
|
|
|
CreatedAt DATETIME NOT NULL
|
|
CONSTRAINT DF_UserCredential_CreatedAt DEFAULT GETDATE(),
|
|
|
|
Expiry DATETIME NOT NULL
|
|
CONSTRAINT DF_UserCredential_Expiry DEFAULT DATEADD(DAY, 90, GETDATE()),
|
|
|
|
Hash NVARCHAR(256) NOT NULL,
|
|
-- uses argon2
|
|
|
|
IsRevoked BIT NOT NULL
|
|
CONSTRAINT DF_UserCredential_IsRevoked DEFAULT 0,
|
|
|
|
RevokedAt DATETIME NULL,
|
|
|
|
RowVersion ROWVERSION,
|
|
|
|
CONSTRAINT PK_UserCredential
|
|
PRIMARY KEY (UserCredentialID),
|
|
|
|
CONSTRAINT FK_UserCredential_UserAccount
|
|
FOREIGN KEY (UserAccountID)
|
|
REFERENCES Auth.UserAccount (UserAccountID)
|
|
ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE
|
|
NONCLUSTERED INDEX IX_UserCredential_UserAccount
|
|
ON Auth.UserCredential(UserAccountID);
|
|
|
|
CREATE
|
|
NONCLUSTERED INDEX IX_UserCredential_Account_Active
|
|
ON Auth.UserCredential(UserAccountID, IsRevoked, Expiry)
|
|
INCLUDE (Hash);
|