diff --git a/src/SqlUpdate/2017-01-03_01_TableAdjustments.sql b/src/SqlUpdate/2017-01-03_01_TableAdjustments.sql index d26b3d3d1..039b97941 100644 --- a/src/SqlUpdate/2017-01-03_01_TableAdjustments.sql +++ b/src/SqlUpdate/2017-01-03_01_TableAdjustments.sql @@ -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 diff --git a/src/SqlUpdate/2017-16-03_01_CipherMigration.sql b/src/SqlUpdate/2017-16-03_01_CipherMigration.sql index dc3fc0ff1..fb06c541a 100644 --- a/src/SqlUpdate/2017-16-03_01_CipherMigration.sql +++ b/src/SqlUpdate/2017-16-03_01_CipherMigration.sql @@ -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