1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

[PM-10368] Drop Group.AccessAll (#4700)

- Add default constraint
- Update sprocs to remove column
- Drop column
This commit is contained in:
Thomas Rittson 2024-09-02 15:01:32 +10:00 committed by GitHub
parent 0d11e03bf7
commit 0da62f9cee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 8368 additions and 29 deletions

View File

@ -103,7 +103,6 @@ public class DatabaseContext : DbContext
var aWebAuthnCredential = builder.Entity<WebAuthnCredential>(); var aWebAuthnCredential = builder.Entity<WebAuthnCredential>();
// Shadow property configurations // Shadow property configurations
eGroup.Property<bool>("AccessAll").HasDefaultValue(false);
builder.Entity<OrganizationUser>() builder.Entity<OrganizationUser>()
.Property<bool>("AccessAll") .Property<bool>("AccessAll")
.HasDefaultValue(false); .HasDefaultValue(false);

View File

@ -2,7 +2,6 @@
@Id UNIQUEIDENTIFIER OUTPUT, @Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100), @Name NVARCHAR(100),
@AccessAll BIT = 0,
@ExternalId NVARCHAR(300), @ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7)
@ -15,7 +14,6 @@ BEGIN
[Id], [Id],
[OrganizationId], [OrganizationId],
[Name], [Name],
[AccessAll],
[ExternalId], [ExternalId],
[CreationDate], [CreationDate],
[RevisionDate] [RevisionDate]
@ -25,7 +23,6 @@ BEGIN
@Id, @Id,
@OrganizationId, @OrganizationId,
@Name, @Name,
@AccessAll,
@ExternalId, @ExternalId,
@CreationDate, @CreationDate,
@RevisionDate @RevisionDate

View File

@ -2,7 +2,6 @@ CREATE PROCEDURE [dbo].[Group_CreateWithCollections]
@Id UNIQUEIDENTIFIER, @Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100), @Name NVARCHAR(100),
@AccessAll BIT = 0,
@ExternalId NVARCHAR(300), @ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7), @RevisionDate DATETIME2(7),
@ -11,7 +10,7 @@ AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
EXEC [dbo].[Group_Create] @Id, @OrganizationId, @Name, @AccessAll, @ExternalId, @CreationDate, @RevisionDate EXEC [dbo].[Group_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
;WITH [AvailableCollectionsCTE] AS( ;WITH [AvailableCollectionsCTE] AS(
SELECT SELECT

View File

@ -2,7 +2,6 @@
@Id UNIQUEIDENTIFIER, @Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100), @Name NVARCHAR(100),
@AccessAll BIT = 0,
@ExternalId NVARCHAR(300), @ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7)
@ -15,7 +14,6 @@ BEGIN
SET SET
[OrganizationId] = @OrganizationId, [OrganizationId] = @OrganizationId,
[Name] = @Name, [Name] = @Name,
[AccessAll] = @AccessAll,
[ExternalId] = @ExternalId, [ExternalId] = @ExternalId,
[CreationDate] = @CreationDate, [CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate [RevisionDate] = @RevisionDate

View File

@ -2,7 +2,6 @@
@Id UNIQUEIDENTIFIER, @Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100), @Name NVARCHAR(100),
@AccessAll BIT = 0,
@ExternalId NVARCHAR(300), @ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7), @RevisionDate DATETIME2(7),
@ -11,7 +10,7 @@ AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
EXEC [dbo].[Group_Update] @Id, @OrganizationId, @Name, @AccessAll, @ExternalId, @CreationDate, @RevisionDate EXEC [dbo].[Group_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
;WITH [AvailableCollectionsCTE] AS( ;WITH [AvailableCollectionsCTE] AS(
SELECT SELECT

View File

@ -2,7 +2,6 @@
[Id] UNIQUEIDENTIFIER NOT NULL, [Id] UNIQUEIDENTIFIER NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL, [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Name] NVARCHAR (100) NOT NULL, [Name] NVARCHAR (100) NOT NULL,
[AccessAll] BIT NOT NULL,
[ExternalId] NVARCHAR (300) NULL, [ExternalId] NVARCHAR (300) NULL,
[CreationDate] DATETIME NOT NULL, [CreationDate] DATETIME NOT NULL,
[RevisionDate] DATETIME NOT NULL, [RevisionDate] DATETIME NOT NULL,

View File

@ -0,0 +1,10 @@
-- Finalise removal of Group.AccessAll column
-- Add default column value
-- Sprocs already have default value for rollback purposes, this just supports dropping the column itself
IF OBJECT_ID('[dbo].[DF_Group_AccessAll]', 'D') IS NULL
BEGIN
ALTER TABLE [dbo].[Group]
ADD CONSTRAINT [DF_Group_AccessAll] DEFAULT (0) FOR [AccessAll];
END
GO

View File

@ -0,0 +1,170 @@
-- Finalise removal of Group.AccessAll column
-- Remove the column from sprocs
CREATE OR ALTER PROCEDURE [dbo].[Group_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Group]
(
[Id],
[OrganizationId],
[Name],
[ExternalId],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@OrganizationId,
@Name,
@ExternalId,
@CreationDate,
@RevisionDate
)
END
GO
CREATE OR ALTER PROCEDURE [dbo].[Group_CreateWithCollections]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Collections AS [dbo].[CollectionAccessSelectionType] READONLY
AS
BEGIN
SET NOCOUNT ON
EXEC [dbo].[Group_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
;WITH [AvailableCollectionsCTE] AS(
SELECT
[Id]
FROM
[dbo].[Collection]
WHERE
[OrganizationId] = @OrganizationId
)
INSERT INTO [dbo].[CollectionGroup]
(
[CollectionId],
[GroupId],
[ReadOnly],
[HidePasswords],
[Manage]
)
SELECT
[Id],
@Id,
[ReadOnly],
[HidePasswords],
[Manage]
FROM
@Collections
WHERE
[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END
GO
CREATE OR ALTER PROCEDURE [dbo].[Group_Update]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Group]
SET
[OrganizationId] = @OrganizationId,
[Name] = @Name,
[ExternalId] = @ExternalId,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO
CREATE OR ALTER PROCEDURE [dbo].[Group_UpdateWithCollections]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Name NVARCHAR(100),
@ExternalId NVARCHAR(300),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Collections AS [dbo].[CollectionAccessSelectionType] READONLY
AS
BEGIN
SET NOCOUNT ON
EXEC [dbo].[Group_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
;WITH [AvailableCollectionsCTE] AS(
SELECT
Id
FROM
[dbo].[Collection]
WHERE
OrganizationId = @OrganizationId
)
MERGE
[dbo].[CollectionGroup] AS [Target]
USING
@Collections AS [Source]
ON
[Target].[CollectionId] = [Source].[Id]
AND [Target].[GroupId] = @Id
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN
INSERT
(
[CollectionId],
[GroupId],
[ReadOnly],
[HidePasswords],
[Manage]
)
VALUES
(
[Source].[Id],
@Id,
[Source].[ReadOnly],
[Source].[HidePasswords],
[Source].[Manage]
)
WHEN MATCHED AND (
[Target].[ReadOnly] != [Source].[ReadOnly]
OR [Target].[HidePasswords] != [Source].[HidePasswords]
OR [Target].[Manage] != [Source].[Manage]
) THEN
UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly],
[Target].[HidePasswords] = [Source].[HidePasswords],
[Target].[Manage] = [Source].[Manage]
WHEN NOT MATCHED BY SOURCE
AND [Target].[GroupId] = @Id THEN
DELETE
;
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END
GO

View File

@ -0,0 +1,25 @@
-- Finalise removal of Group.AccessAll column
-- Drop the column
IF OBJECT_ID('[dbo].[DF_Group_AccessAll]', 'D') IS NOT NULL
BEGIN
ALTER TABLE [dbo].[Group]
DROP CONSTRAINT [DF_Group_AccessAll];
END
GO
IF COL_LENGTH('[dbo].[Group]', 'AccessAll') IS NOT NULL
BEGIN
ALTER TABLE
[dbo].[Group]
DROP COLUMN
[AccessAll]
END
GO
-- Refresh views
IF OBJECT_ID('[dbo].[GroupView]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[GroupView]';
END
GO

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class DropGroupAccessAll : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AccessAll",
table: "Group");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "AccessAll",
table: "Group",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
}
}

View File

@ -17,7 +17,7 @@ namespace Bit.MySqlMigrations.Migrations
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "8.0.7") .HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 64); .HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
@ -1016,11 +1016,6 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("char(36)"); .HasColumnType("char(36)");
b.Property<bool>("AccessAll")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(false);
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class DropGroupAccessAll : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AccessAll",
table: "Group");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "AccessAll",
table: "Group",
type: "boolean",
nullable: false,
defaultValue: false);
}
}

View File

@ -18,7 +18,7 @@ namespace Bit.PostgresMigrations.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:postgresIndetermanisticCollation", "en-u-ks-primary,en-u-ks-primary,icu,False") .HasAnnotation("Npgsql:CollationDefinition:postgresIndetermanisticCollation", "en-u-ks-primary,en-u-ks-primary,icu,False")
.HasAnnotation("ProductVersion", "8.0.7") .HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -1021,11 +1021,6 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("uuid"); .HasColumnType("uuid");
b.Property<bool>("AccessAll")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class DropGroupAccessAll : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AccessAll",
table: "Group");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "AccessAll",
table: "Group",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
}

View File

@ -15,7 +15,7 @@ namespace Bit.SqliteMigrations.Migrations
protected override void BuildModel(ModelBuilder modelBuilder) protected override void BuildModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b => modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{ {
@ -1005,11 +1005,6 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<bool>("AccessAll")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(false);
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT"); .HasColumnType("TEXT");