1
0
mirror of https://github.com/bitwarden/server synced 2026-01-10 20:44:05 +00:00

sql tuning and migrations

This commit is contained in:
Kyle Spearrin
2017-04-13 13:16:15 -04:00
parent bf18a5905d
commit 5a24b6624d
10 changed files with 83 additions and 13 deletions

View File

@@ -0,0 +1,33 @@
-- Get rid of history table
DROP TABLE [History]
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,
[Name] VARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_Folder] PRIMARY KEY CLUSTERED ([Id] ASC)
)
GO
CREATE TABLE [dbo].[FolderCipher] (
[FolderId] UNIQUEIDENTIFIER NOT NULL,
[CipherId] UNIQUEIDENTIFIER NOT NULL,
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([FolderId] ASC, [CipherId] ASC)
)
GO

View File

@@ -1,3 +1,5 @@
-- Step 1, Run each statement individually
insert into folder
select Id, UserId, JSON_VALUE(Data,'$.Name') AS [Name], CreationDate, RevisionDate
from cipher
@@ -12,3 +14,20 @@ insert into favorite
select UserId, [Id]
from cipher
where Favorite = 1
-- Step 2, drop each column
alter table cipher drop constraint [FK_Cipher_Folder]
go
alter table cipher drop column FolderId
go
alter table cipher drop column Favorite
go
-- Step 3, delete old folder ciphers
delete from cipher where [type] = 0