mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[BEEEP] [SM-1059] Add missing auth table indexes to EF config (#3625)
* Add missing indexes to EF auth tables * Add EF migrations
This commit is contained in:
parent
96f9fbb951
commit
880ceafe9f
@ -21,6 +21,10 @@ public class GrantEntityTypeConfiguration : IEntityTypeConfiguration<Grant>
|
||||
.HasIndex(s => s.Key)
|
||||
.IsUnique(true);
|
||||
|
||||
builder
|
||||
.HasIndex(s => s.ExpirationDate)
|
||||
.IsClustered(false);
|
||||
|
||||
builder.ToTable(nameof(Grant));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Auth.Configurations;
|
||||
|
||||
public class SsoUserEntityTypeConfiguration : IEntityTypeConfiguration<SsoUser>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<SsoUser> builder)
|
||||
{
|
||||
builder
|
||||
.HasIndex(su => su.OrganizationId)
|
||||
.IsClustered(false);
|
||||
|
||||
NpgsqlIndexBuilderExtensions.IncludeProperties(
|
||||
builder.HasIndex(su => new { su.OrganizationId, su.ExternalId })
|
||||
.IsUnique()
|
||||
.IsClustered(false),
|
||||
su => su.UserId);
|
||||
|
||||
builder
|
||||
.HasIndex(su => new { su.OrganizationId, su.UserId })
|
||||
.IsUnique()
|
||||
.IsClustered(false);
|
||||
|
||||
builder.ToTable(nameof(SsoUser));
|
||||
}
|
||||
}
|
@ -86,7 +86,6 @@ public class DatabaseContext : DbContext
|
||||
var eProviderUser = builder.Entity<ProviderUser>();
|
||||
var eProviderOrganization = builder.Entity<ProviderOrganization>();
|
||||
var eSsoConfig = builder.Entity<SsoConfig>();
|
||||
var eSsoUser = builder.Entity<SsoUser>();
|
||||
var eTaxRate = builder.Entity<TaxRate>();
|
||||
var eUser = builder.Entity<User>();
|
||||
var eOrganizationApiKey = builder.Entity<OrganizationApiKey>();
|
||||
@ -125,8 +124,8 @@ public class DatabaseContext : DbContext
|
||||
// see https://www.npgsql.org/efcore/misc/collations-and-case-sensitivity.html#database-collation
|
||||
builder.HasCollation(postgresIndetermanisticCollation, locale: "en-u-ks-primary", provider: "icu", deterministic: false);
|
||||
eUser.Property(e => e.Email).UseCollation(postgresIndetermanisticCollation);
|
||||
eSsoUser.Property(e => e.ExternalId).UseCollation(postgresIndetermanisticCollation);
|
||||
builder.Entity<Organization>().Property(e => e.Identifier).UseCollation(postgresIndetermanisticCollation);
|
||||
builder.Entity<SsoUser>().Property(e => e.ExternalId).UseCollation(postgresIndetermanisticCollation);
|
||||
//
|
||||
}
|
||||
|
||||
@ -142,7 +141,6 @@ public class DatabaseContext : DbContext
|
||||
eProviderUser.ToTable(nameof(ProviderUser));
|
||||
eProviderOrganization.ToTable(nameof(ProviderOrganization));
|
||||
eSsoConfig.ToTable(nameof(SsoConfig));
|
||||
eSsoUser.ToTable(nameof(SsoUser));
|
||||
eTaxRate.ToTable(nameof(TaxRate));
|
||||
eOrganizationApiKey.ToTable(nameof(OrganizationApiKey));
|
||||
eOrganizationConnection.ToTable(nameof(OrganizationConnection));
|
||||
|
2398
util/MySqlMigrations/Migrations/20240112180622_AddAuthTableIndexes.Designer.cs
generated
Normal file
2398
util/MySqlMigrations/Migrations/20240112180622_AddAuthTableIndexes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddAuthTableIndexes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "ExternalId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "UserId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant",
|
||||
column: "ExpirationDate");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant");
|
||||
}
|
||||
}
|
@ -3,8 +3,8 @@ using System;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -490,7 +490,7 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.IsRequired()
|
||||
@ -535,6 +535,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("ExpirationDate")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("Key")
|
||||
.IsUnique();
|
||||
|
||||
@ -590,10 +593,20 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrganizationId");
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("OrganizationId", "ExternalId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("Npgsql:IndexInclude", new[] { "UserId" })
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("OrganizationId", "UserId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("SsoUser", (string)null);
|
||||
});
|
||||
|
||||
|
2412
util/PostgresMigrations/Migrations/20240112180915_AddAuthTableIndexes.Designer.cs
generated
Normal file
2412
util/PostgresMigrations/Migrations/20240112180915_AddAuthTableIndexes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddAuthTableIndexes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "ExternalId" },
|
||||
unique: true)
|
||||
.Annotation("Npgsql:IndexInclude", new[] { "UserId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "UserId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant",
|
||||
column: "ExpirationDate");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant");
|
||||
}
|
||||
}
|
@ -541,6 +541,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("ExpirationDate")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("Key")
|
||||
.IsUnique();
|
||||
|
||||
@ -601,10 +604,21 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrganizationId");
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("OrganizationId", "ExternalId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
NpgsqlIndexBuilderExtensions.IncludeProperties(b.HasIndex("OrganizationId", "ExternalId"), new[] { "UserId" });
|
||||
|
||||
b.HasIndex("OrganizationId", "UserId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("SsoUser", (string)null);
|
||||
});
|
||||
|
||||
|
2396
util/SqliteMigrations/Migrations/20240112180610_AddAuthTableIndexes.Designer.cs
generated
Normal file
2396
util/SqliteMigrations/Migrations/20240112180610_AddAuthTableIndexes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddAuthTableIndexes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "ExternalId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser",
|
||||
columns: new[] { "OrganizationId", "UserId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant",
|
||||
column: "ExpirationDate");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_ExternalId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_SsoUser_OrganizationId_UserId",
|
||||
table: "SsoUser");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Grant_ExpirationDate",
|
||||
table: "Grant");
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -487,7 +488,7 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasAnnotation("Sqlite:Autoincrement", true);
|
||||
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.IsRequired()
|
||||
@ -532,6 +533,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.HasKey("Id")
|
||||
.HasAnnotation("SqlServer:Clustered", true);
|
||||
|
||||
b.HasIndex("ExpirationDate")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("Key")
|
||||
.IsUnique();
|
||||
|
||||
@ -587,10 +591,20 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrganizationId");
|
||||
b.HasIndex("OrganizationId")
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("OrganizationId", "ExternalId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("Npgsql:IndexInclude", new[] { "UserId" })
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.HasIndex("OrganizationId", "UserId")
|
||||
.IsUnique()
|
||||
.HasAnnotation("SqlServer:Clustered", false);
|
||||
|
||||
b.ToTable("SsoUser", (string)null);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user