From fd961dfdf6e4de47508d4983ca42b03a56b0c161 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 14 Jan 2017 09:42:07 -0500 Subject: [PATCH] AccountRevisionDate to track changes for a user account. Managed via triggers. --- src/Sql/Sql.sqlproj | 1 + src/Sql/dbo/Stored Procedures/User_Create.sql | 3 +++ .../User_ReadAccountRevisionDateById.sql | 13 +++++++++++++ src/Sql/dbo/Stored Procedures/User_Update.sql | 2 ++ src/Sql/dbo/Tables/Cipher.sql | 15 +++++++++++++++ src/Sql/dbo/Tables/User.sql | 1 + 6 files changed, 35 insertions(+) create mode 100644 src/Sql/dbo/Stored Procedures/User_ReadAccountRevisionDateById.sql diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index 8137664d3..c2022e39d 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -102,5 +102,6 @@ + \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/User_Create.sql b/src/Sql/dbo/Stored Procedures/User_Create.sql index 2ebc7eee1..725ecf850 100644 --- a/src/Sql/dbo/Stored Procedures/User_Create.sql +++ b/src/Sql/dbo/Stored Procedures/User_Create.sql @@ -13,6 +13,7 @@ @TwoFactorRecoveryCode NVARCHAR(32), @EquivalentDomains NVARCHAR(MAX), @ExcludedGlobalEquivalentDomains NVARCHAR(MAX), + @AccountRevisionDate DATETIME2(7), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) AS @@ -35,6 +36,7 @@ BEGIN [TwoFactorRecoveryCode], [EquivalentDomains], [ExcludedGlobalEquivalentDomains], + [AccountRevisionDate], [CreationDate], [RevisionDate] ) @@ -54,6 +56,7 @@ BEGIN @TwoFactorRecoveryCode, @EquivalentDomains, @ExcludedGlobalEquivalentDomains, + @AccountRevisionDate, @CreationDate, @RevisionDate ) diff --git a/src/Sql/dbo/Stored Procedures/User_ReadAccountRevisionDateById.sql b/src/Sql/dbo/Stored Procedures/User_ReadAccountRevisionDateById.sql new file mode 100644 index 000000000..b7dab1dc4 --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/User_ReadAccountRevisionDateById.sql @@ -0,0 +1,13 @@ +CREATE PROCEDURE [dbo].[User_ReadAccountRevisionDateById] + @Id UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + SELECT + [AccountRevisionDate] + FROM + [dbo].[User] + WHERE + [Id] = @Id +END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/User_Update.sql b/src/Sql/dbo/Stored Procedures/User_Update.sql index 50083d6e0..f05c4e5b8 100644 --- a/src/Sql/dbo/Stored Procedures/User_Update.sql +++ b/src/Sql/dbo/Stored Procedures/User_Update.sql @@ -13,6 +13,7 @@ @TwoFactorRecoveryCode NVARCHAR(32), @EquivalentDomains NVARCHAR(MAX), @ExcludedGlobalEquivalentDomains NVARCHAR(MAX), + @AccountRevisionDate DATETIME2(7), @CreationDate DATETIME2(7), @RevisionDate DATETIME2(7) AS @@ -35,6 +36,7 @@ BEGIN [TwoFactorRecoveryCode] = @TwoFactorRecoveryCode, [EquivalentDomains] = @EquivalentDomains, [ExcludedGlobalEquivalentDomains] = @ExcludedGlobalEquivalentDomains, + [AccountRevisionDate] = @AccountRevisionDate, [CreationDate] = @CreationDate, [RevisionDate] = @RevisionDate WHERE diff --git a/src/Sql/dbo/Tables/Cipher.sql b/src/Sql/dbo/Tables/Cipher.sql index 83f30b5a4..52e478450 100644 --- a/src/Sql/dbo/Tables/Cipher.sql +++ b/src/Sql/dbo/Tables/Cipher.sql @@ -42,6 +42,11 @@ BEGIN [CreationDate] FROM INSERTED + + UPDATE + [User] + SET + [AccountRevisionDate] = GETUTCDATE() END GO CREATE TRIGGER [dbo].[Cipher_Updated] @@ -67,6 +72,11 @@ BEGIN [RevisionDate] FROM INSERTED + + UPDATE + [User] + SET + [AccountRevisionDate] = GETUTCDATE() END GO CREATE TRIGGER [dbo].[Cipher_Deleted] @@ -92,4 +102,9 @@ BEGIN GETUTCDATE() FROM DELETED + + UPDATE + [User] + SET + [AccountRevisionDate] = GETUTCDATE() END \ No newline at end of file diff --git a/src/Sql/dbo/Tables/User.sql b/src/Sql/dbo/Tables/User.sql index 2b33f0cb8..3eef87f22 100644 --- a/src/Sql/dbo/Tables/User.sql +++ b/src/Sql/dbo/Tables/User.sql @@ -13,6 +13,7 @@ [TwoFactorRecoveryCode] NVARCHAR (32) NULL, [EquivalentDomains] NVARCHAR (MAX) NULL, [ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL, + [AccountRevisionDate] DATETIME2 (7) NOT NULL, [CreationDate] DATETIME2 (7) NOT NULL, [RevisionDate] DATETIME2 (7) NOT NULL, CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)