1
0
mirror of https://github.com/bitwarden/server synced 2025-12-18 17:23:28 +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,96 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.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: "integer");
migrationBuilder.CreateTable(
name: "PlayData",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PlayId = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: true),
OrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", 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);
});
migrationBuilder.CreateTable(
name: "SeededData",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
RecipeName = table.Column<string>(type: "text", nullable: false),
Data = table.Column<string>(type: "text", nullable: false),
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SeededData", x => x.Id);
});
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: "integer",
nullable: false,
oldClrType: typeof(short),
oldType: "smallint");
}
}

View File

@@ -623,8 +623,8 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<byte>("Type")
.HasColumnType("smallint");
b.Property<int>("WaitTimeDays")
.HasColumnType("integer");
b.Property<short>("WaitTimeDays")
.HasColumnType("smallint");
b.HasKey("Id");
@@ -1590,6 +1590,64 @@ namespace Bit.PostgresMigrations.Migrations
b.ToTable("OrganizationUser", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("OrganizationId")
.HasColumnType("uuid");
b.Property<string>("PlayId")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
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("uuid");
b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("SeededData");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
{
b.Property<Guid>("Id")
@@ -2964,6 +3022,23 @@ namespace Bit.PostgresMigrations.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")