mirror of
https://github.com/bitwarden/server.git
synced 2024-12-30 18:17:36 +01:00
update migration scripts for json favs/folders
This commit is contained in:
parent
a684e03819
commit
94043d5006
@ -5,13 +5,6 @@ GO
|
||||
|
||||
-- Setup new tables
|
||||
|
||||
CREATE TABLE [dbo].[Favorite] (
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_Favorite] PRIMARY KEY CLUSTERED ([UserId] ASC, [CipherId] ASC)
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE [dbo].[Folder] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
@ -22,13 +15,13 @@ CREATE TABLE [dbo].[Folder] (
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE [dbo].[FolderCipher] (
|
||||
[FolderId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([UserId] ASC, [FolderId] ASC, [CipherId] ASC)
|
||||
)
|
||||
-- Setup new columns for cipher changes
|
||||
|
||||
ALTER TABLE [dbo].[Cipher]
|
||||
ADD [Favorites] VARCHAR(MAX) NULL
|
||||
GO
|
||||
|
||||
|
||||
ALTER TABLE [dbo].[Cipher]
|
||||
ADD [Folders] VARCHAR(MAX) NULL
|
||||
GO
|
||||
|
||||
|
@ -5,18 +5,16 @@ select Id, UserId, JSON_VALUE(Data,'$.Name') AS [Name], CreationDate, RevisionDa
|
||||
from cipher
|
||||
where [type] = 0
|
||||
|
||||
insert into foldercipher
|
||||
select FolderId, Id, UserId
|
||||
from cipher
|
||||
where [FolderId] is not null
|
||||
update cipher set
|
||||
Folders = concat('{"', userid, '":"', folderid, '"}')
|
||||
where [userid] is not null
|
||||
and [folderid] is not null
|
||||
|
||||
insert into favorite
|
||||
select UserId, [Id]
|
||||
from cipher
|
||||
where Favorite = 1
|
||||
update cipher set
|
||||
Favorites = concat('{"', userid, '":true}')
|
||||
where [Favorite] = 1
|
||||
|
||||
|
||||
-- Step 2, drop each column
|
||||
-- Step 2, verify data migration from step 1 then drop each column
|
||||
|
||||
alter table cipher drop constraint [FK_Cipher_Folder]
|
||||
go
|
||||
|
Loading…
Reference in New Issue
Block a user