Skip to content

Commit c712df3

Browse files
committed
Created migration scripts for sqlserver and ef core migration to add the ArchivedDate column
1 parent 44ffbc2 commit c712df3

22 files changed

+9661
-38
lines changed

src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ from cg in cg_g.DefaultIfEmpty()
6868
Manage = cu == null ? (cg != null && cg.Manage == true) : cu.Manage == true,
6969
OrganizationUseTotp = o.UseTotp,
7070
c.Reprompt,
71-
c.Key
71+
c.Key,
72+
c.ArchivedDate
7273
};
7374

7475
var query2 = from c in dbContext.Ciphers
@@ -91,7 +92,8 @@ from cg in cg_g.DefaultIfEmpty()
9192
Manage = true,
9293
OrganizationUseTotp = false,
9394
c.Reprompt,
94-
c.Key
95+
c.Key,
96+
c.ArchivedDate
9597
};
9698

9799
var union = query.Union(query2).Select(c => new CipherDetails
@@ -112,7 +114,8 @@ from cg in cg_g.DefaultIfEmpty()
112114
ViewPassword = c.ViewPassword,
113115
Manage = c.Manage,
114116
OrganizationUseTotp = c.OrganizationUseTotp,
115-
Key = c.Key
117+
Key = c.Key,
118+
ArchivedDate = c.ArchivedDate
116119
});
117120
return union;
118121
}

src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId,
479479
ViewPassword = true,
480480
Manage = true,
481481
OrganizationUseTotp = false,
482-
Key = c.Key
482+
Key = c.Key,
483+
ArchivedDate = c.ArchivedDate,
483484
};
484485
}
485486
var ciphers = await cipherDetailsView.ToListAsync();

src/Infrastructure.EntityFramework/Vault/Repositories/Queries/CipherDetailsQuery.cs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
3434
FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.ToLowerInvariant().Contains(_userId.Value.ToString())) ?
3535
null :
3636
CoreHelpers.LoadClassFromJsonData<Dictionary<Guid, Guid>>(c.Folders)[_userId.Value],
37+
ArchivedDate = c.ArchivedDate,
3738
};
3839
return query;
3940
}

src/Sql/Vault/dbo/Functions/CipherDetails.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SELECT
2727
END [FolderId],
2828
C.[DeletedDate],
2929
C.[Reprompt],
30-
C.[Key]
30+
C.[Key],
31+
C.[ArchivedDate]
3132
FROM
32-
[dbo].[Cipher] C
33+
[dbo].[Cipher] C

src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_Create.sql

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
@OrganizationUseTotp BIT, -- not used
1818
@DeletedDate DATETIME2(7),
1919
@Reprompt TINYINT,
20-
@Key VARCHAR(MAX) = NULL
20+
@Key VARCHAR(MAX) = NULL,
21+
@ArchivedDate DATETIME2(7) = NULL
2122
AS
2223
BEGIN
2324
SET NOCOUNT ON
@@ -38,7 +39,8 @@ BEGIN
3839
[RevisionDate],
3940
[DeletedDate],
4041
[Reprompt],
41-
[Key]
42+
[Key],
43+
[ArchivedDate]
4244
)
4345
VALUES
4446
(
@@ -53,7 +55,8 @@ BEGIN
5355
@RevisionDate,
5456
@DeletedDate,
5557
@Reprompt,
56-
@Key
58+
@Key,
59+
@ArchivedDate
5760
)
5861

5962
IF @OrganizationId IS NOT NULL

src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_CreateWithCollections.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
@DeletedDate DATETIME2(7),
1919
@Reprompt TINYINT,
2020
@Key VARCHAR(MAX) = NULL,
21-
@CollectionIds AS [dbo].[GuidIdArray] READONLY
21+
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
22+
@ArchivedDate DATETIME2(7) = NULL
2223
AS
2324
BEGIN
2425
SET NOCOUNT ON
2526

2627
EXEC [dbo].[CipherDetails_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
2728
@Attachments, @CreationDate, @RevisionDate, @FolderId, @Favorite, @Edit, @ViewPassword, @Manage,
28-
@OrganizationUseTotp, @DeletedDate, @Reprompt, @Key
29+
@OrganizationUseTotp, @DeletedDate, @Reprompt, @Key, @ArchivedDate
2930

3031
DECLARE @UpdateCollectionsSuccess INT
3132
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds

src/Sql/Vault/dbo/Stored Procedures/Cipher/CipherDetails_Update.sql

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
@OrganizationUseTotp BIT, -- not used
1818
@DeletedDate DATETIME2(2),
1919
@Reprompt TINYINT,
20-
@Key VARCHAR(MAX) = NULL
20+
@Key VARCHAR(MAX) = NULL,
21+
@ArchivedDate DATETIME2(7) = NULL
2122
AS
2223
BEGIN
2324
SET NOCOUNT ON
@@ -55,7 +56,8 @@ BEGIN
5556
[CreationDate] = @CreationDate,
5657
[RevisionDate] = @RevisionDate,
5758
[DeletedDate] = @DeletedDate,
58-
[Key] = @Key
59+
[Key] = @Key,
60+
[ArchivedDate] = @ArchivedDate
5961
WHERE
6062
[Id] = @Id
6163

src/Sql/Vault/dbo/Stored Procedures/Cipher/Cipher_Create.sql

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
@RevisionDate DATETIME2(7),
1212
@DeletedDate DATETIME2(7),
1313
@Reprompt TINYINT,
14-
@Key VARCHAR(MAX) = NULL
14+
@Key VARCHAR(MAX) = NULL,
15+
@ArchivedDate DATETIME2(7) = NULL
1516
AS
1617
BEGIN
1718
SET NOCOUNT ON
@@ -30,7 +31,8 @@ BEGIN
3031
[RevisionDate],
3132
[DeletedDate],
3233
[Reprompt],
33-
[Key]
34+
[Key],
35+
[ArchivedDate]
3436
)
3537
VALUES
3638
(
@@ -46,7 +48,8 @@ BEGIN
4648
@RevisionDate,
4749
@DeletedDate,
4850
@Reprompt,
49-
@Key
51+
@Key,
52+
@ArchivedDate
5053
)
5154

5255
IF @OrganizationId IS NOT NULL

src/Sql/Vault/dbo/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
@DeletedDate DATETIME2(7),
1313
@Reprompt TINYINT,
1414
@Key VARCHAR(MAX) = NULL,
15-
@CollectionIds AS [dbo].[GuidIdArray] READONLY
15+
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
16+
@ArchivedDate DATETIME2(7) = NULL
1617
AS
1718
BEGIN
1819
SET NOCOUNT ON
1920

2021
EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
21-
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key
22+
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate
2223

2324
DECLARE @UpdateCollectionsSuccess INT
2425
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
25-
END
26+
END

src/Sql/Vault/dbo/Stored Procedures/Cipher/Cipher_Update.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
@RevisionDate DATETIME2(7),
1212
@DeletedDate DATETIME2(7),
1313
@Reprompt TINYINT,
14-
@Key VARCHAR(MAX) = NULL
14+
@Key VARCHAR(MAX) = NULL,
15+
@ArchivedDate DATETIME2(7) = NULL
1516
AS
1617
BEGIN
1718
SET NOCOUNT ON
@@ -30,7 +31,8 @@ BEGIN
3031
[RevisionDate] = @RevisionDate,
3132
[DeletedDate] = @DeletedDate,
3233
[Reprompt] = @Reprompt,
33-
[Key] = @Key
34+
[Key] = @Key,
35+
[ArchivedDate] = @ArchivedDate
3436
WHERE
3537
[Id] = @Id
3638

@@ -42,4 +44,4 @@ BEGIN
4244
BEGIN
4345
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
4446
END
45-
END
47+
END

src/Sql/Vault/dbo/Stored Procedures/Cipher/Cipher_UpdateWithCollections.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
@DeletedDate DATETIME2(7),
1313
@Reprompt TINYINT,
1414
@Key VARCHAR(MAX) = NULL,
15-
@CollectionIds AS [dbo].[GuidIdArray] READONLY
15+
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
16+
@ArchivedDate DATETIME2(7) = NULL
1617
AS
1718
BEGIN
1819
SET NOCOUNT ON
@@ -37,8 +38,7 @@ BEGIN
3738
[Data] = @Data,
3839
[Attachments] = @Attachments,
3940
[RevisionDate] = @RevisionDate,
40-
[DeletedDate] = @DeletedDate,
41-
[Key] = @Key
41+
[DeletedDate] = @DeletedDate, [Key] = @Key, [ArchivedDate] = @ArchivedDate
4242
-- No need to update CreationDate, Favorites, Folders, or Type since that data will not change
4343
WHERE
4444
[Id] = @Id
@@ -54,4 +54,4 @@ BEGIN
5454
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
5555

5656
SELECT 0 -- 0 = Success
57-
END
57+
END

src/Sql/Vault/dbo/Tables/Cipher.sql

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ CREATE TABLE [dbo].[Cipher] (
1313
[DeletedDate] DATETIME2 (7) NULL,
1414
[Reprompt] TINYINT NULL,
1515
[Key] VARCHAR(MAX) NULL,
16+
[ArchivedDate] DATETIME2
17+
(
18+
7
19+
) NULL,
1620
CONSTRAINT [PK_Cipher] PRIMARY KEY CLUSTERED ([Id] ASC),
1721
CONSTRAINT [FK_Cipher_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
1822
CONSTRAINT [FK_Cipher_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
@@ -34,3 +38,8 @@ GO
3438
CREATE NONCLUSTERED INDEX [IX_Cipher_DeletedDate]
3539
ON [dbo].[Cipher]([DeletedDate] ASC);
3640

41+
GO
42+
CREATE
43+
NONCLUSTERED INDEX [IX_Cipher_ArchivedDate]
44+
ON [dbo].[Cipher]([ArchivedDate] ASC);
45+

0 commit comments

Comments
 (0)