1
0
mirror of https://github.com/bitwarden/server synced 2026-01-06 18:43:36 +00:00

Create PlayData table and services

Shift from seeded data tracking that is all server-side to play ids and x-play-id headers that are appended from the clients to track entities added by tests.
This commit is contained in:
Matt Gibson
2025-11-04 16:26:06 -08:00
parent 3f22adcbf2
commit e96e70cc22
31 changed files with 11448 additions and 9 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class _20251104_00_PlayData : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<short>(
name: "WaitTimeDays",
table: "EmergencyAccess",
type: "smallint",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.CreateTable(
name: "PlayData",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
PlayId = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
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.ForeignKey(
name: "FK_PlayData_Organization_OrganizationId",
column: x => x.OrganizationId,
principalTable: "Organization",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlayData_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "SeededData",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
RecipeName = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Data = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SeededData", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_PlayData_OrganizationId",
table: "PlayData",
column: "OrganizationId");
migrationBuilder.CreateIndex(
name: "IX_PlayData_PlayId",
table: "PlayData",
column: "PlayId");
migrationBuilder.CreateIndex(
name: "IX_PlayData_UserId",
table: "PlayData",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PlayData");
migrationBuilder.DropTable(
name: "SeededData");
migrationBuilder.AlterColumn<int>(
name: "WaitTimeDays",
table: "EmergencyAccess",
type: "int",
nullable: false,
oldClrType: typeof(short),
oldType: "smallint");
}
}

View File

@@ -620,8 +620,8 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<byte>("Type")
.HasColumnType("tinyint unsigned");
b.Property<int>("WaitTimeDays")
.HasColumnType("int");
b.Property<short>("WaitTimeDays")
.HasColumnType("smallint");
b.HasKey("Id");
@@ -1585,6 +1585,64 @@ namespace Bit.MySqlMigrations.Migrations
b.ToTable("OrganizationUser", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
{
b.Property<Guid>("Id")
.HasColumnType("char(36)");
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)");
b.Property<Guid?>("OrganizationId")
.HasColumnType("char(36)");
b.Property<string>("PlayId")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<Guid?>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("PlayId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("PlayData", null, t =>
{
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
});
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SeededData", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("RecipeName")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("SeededData");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
{
b.Property<Guid>("Id")
@@ -2958,6 +3016,23 @@ namespace Bit.MySqlMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
.WithMany()
.HasForeignKey("OrganizationId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Organization");
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")