mirror of
https://github.com/bitwarden/server
synced 2026-01-21 03:43:53 +00:00
Rename PlayData -> PlayItem
This is still a join table, but the Data suffix was colliding with the concept of a JSON transfer model. The PlayItem name is designed to indicate that these records are not Play entities, but indications that a given Item (user or organization for now) is associated with a given Play
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
-- Create PlayData table
|
||||
IF OBJECT_ID('dbo.PlayData') IS NULL
|
||||
-- Create PlayItem table
|
||||
IF OBJECT_ID('dbo.PlayItem') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE [dbo].[PlayData] (
|
||||
CREATE TABLE [dbo].[PlayItem] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[PlayId] NVARCHAR (256) NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_PlayData] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_PlayData_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_PlayData_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [CK_PlayData_UserOrOrganization] CHECK (([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL))
|
||||
CONSTRAINT [PK_PlayItem] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_PlayItem_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_PlayItem_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [CK_PlayItem_UserOrOrganization] CHECK (([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL))
|
||||
);
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayData_PlayId]
|
||||
ON [dbo].[PlayData]([PlayId] ASC);
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayItem_PlayId]
|
||||
ON [dbo].[PlayItem]([PlayId] ASC);
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayData_UserId]
|
||||
ON [dbo].[PlayData]([UserId] ASC);
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayItem_UserId]
|
||||
ON [dbo].[PlayItem]([UserId] ASC);
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayData_OrganizationId]
|
||||
ON [dbo].[PlayData]([OrganizationId] ASC);
|
||||
CREATE NONCLUSTERED INDEX [IX_PlayItem_OrganizationId]
|
||||
ON [dbo].[PlayItem]([OrganizationId] ASC);
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create PlayData_Create stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayData_Create]
|
||||
-- Create PlayItem_Create stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayItem_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@PlayId NVARCHAR(256),
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@@ -35,7 +35,7 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[PlayData]
|
||||
INSERT INTO [dbo].[PlayItem]
|
||||
(
|
||||
[Id],
|
||||
[PlayId],
|
||||
@@ -54,8 +54,8 @@ BEGIN
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create PlayData_ReadByPlayId stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayData_ReadByPlayId]
|
||||
-- Create PlayItem_ReadByPlayId stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayItem_ReadByPlayId]
|
||||
@PlayId NVARCHAR(256)
|
||||
AS
|
||||
BEGIN
|
||||
@@ -68,14 +68,14 @@ BEGIN
|
||||
[OrganizationId],
|
||||
[CreationDate]
|
||||
FROM
|
||||
[dbo].[PlayData]
|
||||
[dbo].[PlayItem]
|
||||
WHERE
|
||||
[PlayId] = @PlayId
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create PlayData_DeleteByPlayId stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayData_DeleteByPlayId]
|
||||
-- Create PlayItem_DeleteByPlayId stored procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[PlayItem_DeleteByPlayId]
|
||||
@PlayId NVARCHAR(256)
|
||||
AS
|
||||
BEGIN
|
||||
@@ -83,7 +83,7 @@ BEGIN
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[PlayData]
|
||||
[dbo].[PlayItem]
|
||||
WHERE
|
||||
[PlayId] = @PlayId
|
||||
END
|
||||
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Bit.MySqlMigrations.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20251118024031_PlayData")]
|
||||
partial class PlayData
|
||||
[Migration("20251118024031_PlayItem")]
|
||||
partial class PlayItem
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -1624,7 +1624,7 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("char(36)");
|
||||
@@ -1654,9 +1654,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3033,7 +3033,7 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Bit.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class PlayData : Migration
|
||||
public partial class PlayItem : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -19,7 +19,7 @@ public partial class PlayData : Migration
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PlayData",
|
||||
name: "PlayItem",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||
@@ -31,16 +31,16 @@ public partial class PlayData : Migration
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.PrimaryKey("PK_PlayItem", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_Organization_OrganizationId",
|
||||
name: "FK_PlayItem_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_User_UserId",
|
||||
name: "FK_PlayItem_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
@@ -49,18 +49,18 @@ public partial class PlayData : Migration
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_OrganizationId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_OrganizationId",
|
||||
table: "PlayItem",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_PlayId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_PlayId",
|
||||
table: "PlayItem",
|
||||
column: "PlayId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_UserId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_UserId",
|
||||
table: "PlayItem",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public partial class PlayData : Migration
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlayData");
|
||||
name: "PlayItem");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "WaitTimeDays",
|
||||
@@ -1627,7 +1627,7 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("char(36)");
|
||||
@@ -1657,9 +1657,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3039,7 +3039,7 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
|
||||
@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Bit.PostgresMigrations.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20251118024041_PlayData")]
|
||||
partial class PlayData
|
||||
[Migration("20251118024041_PlayItem")]
|
||||
partial class PlayItem
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -1629,7 +1629,7 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid");
|
||||
@@ -1659,9 +1659,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3039,7 +3039,7 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class PlayData : Migration
|
||||
public partial class PlayItem : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@@ -19,7 +19,7 @@ public partial class PlayData : Migration
|
||||
oldType: "integer");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PlayData",
|
||||
name: "PlayItem",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
@@ -30,16 +30,16 @@ public partial class PlayData : Migration
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.PrimaryKey("PK_PlayItem", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_Organization_OrganizationId",
|
||||
name: "FK_PlayItem_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_User_UserId",
|
||||
name: "FK_PlayItem_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
@@ -47,18 +47,18 @@ public partial class PlayData : Migration
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_OrganizationId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_OrganizationId",
|
||||
table: "PlayItem",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_PlayId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_PlayId",
|
||||
table: "PlayItem",
|
||||
column: "PlayId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_UserId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_UserId",
|
||||
table: "PlayItem",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public partial class PlayData : Migration
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlayData");
|
||||
name: "PlayItem");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "WaitTimeDays",
|
||||
@@ -1632,7 +1632,7 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid");
|
||||
@@ -1662,9 +1662,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3045,7 +3045,7 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
|
||||
@@ -9,16 +9,16 @@ public class DestroySceneCommand(
|
||||
DatabaseContext databaseContext,
|
||||
ILogger<DestroySceneCommand> logger,
|
||||
IUserRepository userRepository,
|
||||
IPlayDataRepository playDataRepository,
|
||||
IPlayItemRepository playItemRepository,
|
||||
IOrganizationRepository organizationRepository) : IDestroySceneCommand
|
||||
{
|
||||
public async Task<object?> DestroyAsync(string playId)
|
||||
{
|
||||
// Note, delete cascade will remove PlayData entries
|
||||
// Note, delete cascade will remove PlayItem entries
|
||||
|
||||
var playData = await playDataRepository.GetByPlayIdAsync(playId);
|
||||
var userIds = playData.Select(pd => pd.UserId).Distinct().ToList();
|
||||
var organizationIds = playData.Select(pd => pd.OrganizationId).Distinct().ToList();
|
||||
var playItem = await playItemRepository.GetByPlayIdAsync(playId);
|
||||
var userIds = playItem.Select(pd => pd.UserId).Distinct().ToList();
|
||||
var organizationIds = playItem.Select(pd => pd.OrganizationId).Distinct().ToList();
|
||||
|
||||
// Delete Users before Organizations to respect foreign key constraints
|
||||
if (userIds.Count > 0)
|
||||
|
||||
@@ -7,7 +7,7 @@ public class GetAllPlayIdsQuery(DatabaseContext databaseContext) : IGetAllPlayId
|
||||
{
|
||||
public List<string> GetAllPlayIds()
|
||||
{
|
||||
return databaseContext.PlayData
|
||||
return databaseContext.PlayItem
|
||||
.Select(pd => pd.PlayId)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
@@ -85,9 +85,7 @@ curl -X POST http://localhost:5000/query \
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
[
|
||||
"/accept-emergency?..."
|
||||
]
|
||||
["/accept-emergency?..."]
|
||||
```
|
||||
|
||||
### Destroying Seeded Data
|
||||
@@ -148,7 +146,7 @@ The SeederApi requires the following configuration:
|
||||
## Play ID Tracking
|
||||
|
||||
Certain entities such as Users and Organizations are tracked when created by a request including a PlayId. This enables
|
||||
entities to be deleted after using the PlayId.
|
||||
entities to be deleted after using the PlayId.
|
||||
|
||||
### The X-Play-Id Header
|
||||
|
||||
@@ -168,7 +166,7 @@ When `TestPlayIdTrackingEnabled` is enabled in GlobalSettings, the `PlayIdMiddle
|
||||
1. **Extracts** the `X-Play-Id` header from incoming requests
|
||||
2. **Sets** the play ID in the `PlayIdService` for the request scope
|
||||
3. **Tracks** all entities (users, organizations, etc.) created during the request
|
||||
4. **Associates** them with the play ID in the `PlayData` table
|
||||
4. **Associates** them with the play ID in the `PlayItem` table
|
||||
5. **Enables** complete cleanup via the delete endpoints
|
||||
|
||||
This tracking works for **any API request** that includes the `X-Play-Id` header, not just SeederApi endpoints. This means
|
||||
|
||||
@@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Bit.SqliteMigrations.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20251118024036_PlayData")]
|
||||
partial class PlayData
|
||||
[Migration("20251118024036_PlayItem")]
|
||||
partial class PlayItem
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -1613,7 +1613,7 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -1643,9 +1643,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3022,7 +3022,7 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
@@ -5,13 +5,13 @@
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class PlayData : Migration
|
||||
public partial class PlayItem : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PlayData",
|
||||
name: "PlayItem",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
@@ -22,16 +22,16 @@ public partial class PlayData : Migration
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.PrimaryKey("PK_PlayItem", x => x.Id);
|
||||
table.CheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_Organization_OrganizationId",
|
||||
name: "FK_PlayItem_Organization_OrganizationId",
|
||||
column: x => x.OrganizationId,
|
||||
principalTable: "Organization",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlayData_User_UserId",
|
||||
name: "FK_PlayItem_User_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "User",
|
||||
principalColumn: "Id",
|
||||
@@ -39,18 +39,18 @@ public partial class PlayData : Migration
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_OrganizationId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_OrganizationId",
|
||||
table: "PlayItem",
|
||||
column: "OrganizationId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_PlayId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_PlayId",
|
||||
table: "PlayItem",
|
||||
column: "PlayId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlayData_UserId",
|
||||
table: "PlayData",
|
||||
name: "IX_PlayItem_UserId",
|
||||
table: "PlayItem",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
@@ -58,6 +58,6 @@ public partial class PlayData : Migration
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlayData");
|
||||
name: "PlayItem");
|
||||
}
|
||||
}
|
||||
@@ -1616,7 +1616,7 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.ToTable("OrganizationUser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -1646,9 +1646,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.HasIndex("UserId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("PlayData", null, t =>
|
||||
b.ToTable("PlayItem", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
t.HasCheckConstraint("CK_PlayItem_UserOrOrganization", "(\"UserId\" IS NOT NULL AND \"OrganizationId\" IS NULL) OR (\"UserId\" IS NULL AND \"OrganizationId\" IS NOT NULL)");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3028,7 +3028,7 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayItem", b =>
|
||||
{
|
||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||
.WithMany()
|
||||
|
||||
Reference in New Issue
Block a user