diff --git a/src/Infrastructure.EntityFramework/Auth/Configurations/GrantEntityTypeConfiguration.cs b/src/Infrastructure.EntityFramework/Auth/Configurations/GrantEntityTypeConfiguration.cs index 06c5eac0a..599be37a8 100644 --- a/src/Infrastructure.EntityFramework/Auth/Configurations/GrantEntityTypeConfiguration.cs +++ b/src/Infrastructure.EntityFramework/Auth/Configurations/GrantEntityTypeConfiguration.cs @@ -12,6 +12,10 @@ public class GrantEntityTypeConfiguration : IEntityTypeConfiguration .HasKey(s => s.Id) .IsClustered(); + builder + .Property(s => s.Id) + .UseIdentityColumn(); + builder .HasIndex(s => s.Key) .IsUnique(true); diff --git a/src/Sql/Auth/dbo/Tables/Grant.sql b/src/Sql/Auth/dbo/Tables/Grant.sql index 55d1b9b34..2036f11e7 100644 --- a/src/Sql/Auth/dbo/Tables/Grant.sql +++ b/src/Sql/Auth/dbo/Tables/Grant.sql @@ -1,6 +1,6 @@ CREATE TABLE [dbo].[Grant] ( - [Id] INT NOT NULL IDENTITY, + [Id] INT NOT NULL IDENTITY(1,1), [Key] NVARCHAR (200) NOT NULL, [Type] NVARCHAR (50) NOT NULL, [SubjectId] NVARCHAR (200) NULL, diff --git a/util/MySqlMigrations/Migrations/20231214162533_GrantIdWithIndexes.cs b/util/MySqlMigrations/Migrations/20231214162533_GrantIdWithIndexes.cs index 684218411..c9fd5638b 100644 --- a/util/MySqlMigrations/Migrations/20231214162533_GrantIdWithIndexes.cs +++ b/util/MySqlMigrations/Migrations/20231214162533_GrantIdWithIndexes.cs @@ -1,5 +1,4 @@ -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable @@ -73,13 +72,7 @@ public partial class GrantIdWithIndexes : Migration .Annotation("MySql:CharSet", "utf8mb4") .OldAnnotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.AddColumn( - name: "Id", - table: "Grant", - type: "int", - nullable: false, - defaultValue: 0) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + migrationBuilder.Sql("ALTER TABLE `Grant` ADD COLUMN `Id` INT AUTO_INCREMENT UNIQUE;"); migrationBuilder.AddPrimaryKey( name: "PK_Grant", diff --git a/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs b/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs index 17af8ed27..93b5f3653 100644 --- a/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs +++ b/util/MySqlMigrations/Migrations/DatabaseContextModelSnapshot.cs @@ -3,6 +3,7 @@ using System; using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable @@ -488,7 +489,8 @@ namespace Bit.MySqlMigrations.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("int") + .HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); b.Property("ClientId") .IsRequired() diff --git a/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs b/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs index 36004bf71..569f9809a 100644 --- a/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs +++ b/util/SqliteMigrations/Migrations/DatabaseContextModelSnapshot.cs @@ -486,7 +486,8 @@ namespace Bit.SqliteMigrations.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("INTEGER") + .HasAnnotation("Sqlite:Autoincrement", true); b.Property("ClientId") .IsRequired()