Skip to content

Commit 2b742b0

Browse files
cyprain-okekeclaudeamorask-bitwardenconnerbw
authored
[PM-27605] Populate MaxStorageGbIncreased for storage increase from 1GB to 5GB. (#6579)
* Add transition migration to populate MaxStorageGbIncreased This migration populates the MaxStorageGbIncreased column for Users and Organizations by setting it to MaxStorageGb + 4, representing the storage increase from 1GB to 5GB. This migration depends on PM-27603 being deployed first to create the MaxStorageGbIncreased column. Target release: January 6th, 2026 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Using batched updates to reduce lock * Add changes base on ticket adjustment * Added the dependency check * Add temporary index for performance * Resolved the conflict * resolve the syntax error * Update the migration script * Rename the file to updated date * Revert the existing merge file change * revert the change * revert renaming * rename file to updated date * Add the column after renaming * Rename other migration file to set current date --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Alex Morask <amorask@bitwarden.com> Co-authored-by: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com>
1 parent 3511ece commit 2b742b0

6 files changed

Lines changed: 733 additions & 6 deletions

File tree

src/Sql/dbo/Stored Procedures/Organization_Create.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ BEGIN
128128
[UseAdminSponsoredFamilies],
129129
[SyncSeats],
130130
[UseAutomaticUserConfirmation],
131-
[UsePhishingBlocker]
131+
[UsePhishingBlocker],
132+
[MaxStorageGbIncreased]
132133
)
133134
VALUES
134135
(
@@ -193,6 +194,7 @@ BEGIN
193194
@UseAdminSponsoredFamilies,
194195
@SyncSeats,
195196
@UseAutomaticUserConfirmation,
196-
@UsePhishingBlocker
197+
@UsePhishingBlocker,
198+
@MaxStorageGb
197199
);
198200
END

src/Sql/dbo/Stored Procedures/Organization_Update.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ BEGIN
128128
[UseAdminSponsoredFamilies] = @UseAdminSponsoredFamilies,
129129
[SyncSeats] = @SyncSeats,
130130
[UseAutomaticUserConfirmation] = @UseAutomaticUserConfirmation,
131-
[UsePhishingBlocker] = @UsePhishingBlocker
131+
[UsePhishingBlocker] = @UsePhishingBlocker,
132+
[MaxStorageGbIncreased] = @MaxStorageGb
132133
WHERE
133134
[Id] = @Id;
134135
END

src/Sql/dbo/Stored Procedures/User_Create.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ BEGIN
9696
[VerifyDevices],
9797
[SecurityState],
9898
[SecurityVersion],
99-
[SignedPublicKey]
99+
[SignedPublicKey],
100+
[MaxStorageGbIncreased]
100101
)
101102
VALUES
102103
(
@@ -145,6 +146,7 @@ BEGIN
145146
@VerifyDevices,
146147
@SecurityState,
147148
@SecurityVersion,
148-
@SignedPublicKey
149+
@SignedPublicKey,
150+
@MaxStorageGb
149151
)
150152
END

src/Sql/dbo/Stored Procedures/User_Update.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ BEGIN
9696
[VerifyDevices] = @VerifyDevices,
9797
[SecurityState] = @SecurityState,
9898
[SecurityVersion] = @SecurityVersion,
99-
[SignedPublicKey] = @SignedPublicKey
99+
[SignedPublicKey] = @SignedPublicKey,
100+
[MaxStorageGbIncreased] = @MaxStorageGb
100101
WHERE
101102
[Id] = @Id
102103
END
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
-- ========================================
2+
-- Dependency Validation
3+
-- ========================================
4+
IF NOT EXISTS (
5+
SELECT 1 FROM sys.columns
6+
WHERE object_id = OBJECT_ID('[dbo].[User]')
7+
AND name = 'MaxStorageGbIncreased'
8+
)
9+
BEGIN
10+
RAISERROR('MaxStorageGbIncreased column does not exist in User table. PM-27603 must be deployed first.', 16, 1);
11+
RETURN;
12+
END;
13+
14+
IF NOT EXISTS (
15+
SELECT 1 FROM sys.columns
16+
WHERE object_id = OBJECT_ID('[dbo].[Organization]')
17+
AND name = 'MaxStorageGbIncreased'
18+
)
19+
BEGIN
20+
RAISERROR('MaxStorageGbIncreased column does not exist in Organization table. PM-27603 must be deployed first.', 16, 1);
21+
RETURN;
22+
END;
23+
GO
24+
25+
-- ========================================
26+
-- User Table Migration
27+
-- ========================================
28+
29+
-- Create temporary index for performance
30+
IF NOT EXISTS (
31+
SELECT 1
32+
FROM sys.indexes
33+
WHERE object_id = OBJECT_ID('dbo.User')
34+
AND name = 'IX_TEMP_User_MaxStorageGb_MaxStorageGbIncreased'
35+
)
36+
BEGIN
37+
PRINT 'Creating temporary index on User table...';
38+
CREATE INDEX IX_TEMP_User_MaxStorageGb_MaxStorageGbIncreased
39+
ON [dbo].[User]([MaxStorageGb], [MaxStorageGbIncreased]);
40+
PRINT 'Temporary index created.';
41+
END
42+
GO
43+
44+
-- Populate MaxStorageGbIncreased for Users in batches
45+
DECLARE @BatchSize INT = 5000;
46+
DECLARE @RowsAffected INT = 1;
47+
DECLARE @TotalUpdated INT = 0;
48+
49+
PRINT 'Starting User table update...';
50+
51+
WHILE @RowsAffected > 0
52+
BEGIN
53+
UPDATE TOP (@BatchSize) [dbo].[User]
54+
SET [MaxStorageGbIncreased] = [MaxStorageGb] + 4
55+
WHERE [MaxStorageGb] IS NOT NULL
56+
AND [MaxStorageGbIncreased] IS NULL;
57+
58+
SET @RowsAffected = @@ROWCOUNT;
59+
SET @TotalUpdated = @TotalUpdated + @RowsAffected;
60+
61+
PRINT 'Users updated: ' + CAST(@TotalUpdated AS VARCHAR(10));
62+
63+
WAITFOR DELAY '00:00:00.100'; -- 100ms delay to reduce contention
64+
END
65+
66+
PRINT 'User table update complete. Total rows updated: ' + CAST(@TotalUpdated AS VARCHAR(10));
67+
GO
68+
69+
-- Drop temporary index
70+
DROP INDEX IF EXISTS [dbo].[User].[IX_TEMP_User_MaxStorageGb_MaxStorageGbIncreased];
71+
PRINT 'Temporary index on User table dropped.';
72+
GO
73+
74+
-- ========================================
75+
-- Organization Table Migration
76+
-- ========================================
77+
78+
-- Create temporary index for performance
79+
IF NOT EXISTS (
80+
SELECT 1
81+
FROM sys.indexes
82+
WHERE object_id = OBJECT_ID('dbo.Organization')
83+
AND name = 'IX_TEMP_Organization_MaxStorageGb_MaxStorageGbIncreased'
84+
)
85+
BEGIN
86+
PRINT 'Creating temporary index on Organization table...';
87+
CREATE INDEX IX_TEMP_Organization_MaxStorageGb_MaxStorageGbIncreased
88+
ON [dbo].[Organization]([MaxStorageGb], [MaxStorageGbIncreased]);
89+
PRINT 'Temporary index created.';
90+
END
91+
GO
92+
93+
-- Populate MaxStorageGbIncreased for Organizations in batches
94+
DECLARE @BatchSize INT = 5000;
95+
DECLARE @RowsAffected INT = 1;
96+
DECLARE @TotalUpdated INT = 0;
97+
98+
PRINT 'Starting Organization table update...';
99+
100+
WHILE @RowsAffected > 0
101+
BEGIN
102+
UPDATE TOP (@BatchSize) [dbo].[Organization]
103+
SET [MaxStorageGbIncreased] = [MaxStorageGb] + 4
104+
WHERE [MaxStorageGb] IS NOT NULL
105+
AND [MaxStorageGbIncreased] IS NULL;
106+
107+
SET @RowsAffected = @@ROWCOUNT;
108+
SET @TotalUpdated = @TotalUpdated + @RowsAffected;
109+
110+
PRINT 'Organizations updated: ' + CAST(@TotalUpdated AS VARCHAR(10));
111+
112+
WAITFOR DELAY '00:00:00.100'; -- 100ms delay to reduce contention
113+
END
114+
115+
PRINT 'Organization table update complete. Total rows updated: ' + CAST(@TotalUpdated AS VARCHAR(10));
116+
GO
117+
118+
-- Drop temporary index
119+
DROP INDEX IF EXISTS [dbo].[Organization].[IX_TEMP_Organization_MaxStorageGb_MaxStorageGbIncreased];
120+
PRINT 'Temporary index on Organization table dropped.';
121+
GO

0 commit comments

Comments
 (0)