diff --git a/src/FiscalOS.Infra/Data/AppDbContext.cs b/src/FiscalOS.Infra/Data/AppDbContext.cs index c57edf8..efd238e 100644 --- a/src/FiscalOS.Infra/Data/AppDbContext.cs +++ b/src/FiscalOS.Infra/Data/AppDbContext.cs @@ -45,7 +45,6 @@ public sealed class AppDbContext(IOptions ctxOptions) : DbC modelBuilder.Entity(static eb => { - eb.HasMany(static u => u.RefreshTokens) .WithOne(static t => t.User) .HasForeignKey(static t => t.UserId) @@ -56,10 +55,12 @@ public sealed class AppDbContext(IOptions ctxOptions) : DbC eb.Property(static u => u.HashedPassword); }); + modelBuilder.Entity(static eb => { eb.Property(static t => t.Id); eb.Property(static t => t.ExpiresAt); + eb.Property(static t => t.UserId); eb.Property(static t => t.Token); eb.HasIndex(static t => t.Token).IsUnique(); diff --git a/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.Designer.cs b/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.Designer.cs new file mode 100644 index 0000000..6042d65 --- /dev/null +++ b/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.Designer.cs @@ -0,0 +1,101 @@ +// +using System; +using FiscalOS.Infra.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FiscalOS.Infra.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260203115122_AddUserIdPropToRefreshToken")] + partial class AddUserIdPropToRefreshToken + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.2"); + + modelBuilder.Entity("FiscalOS.Core.Identity.RefreshToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Token") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAt") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Token") + .IsUnique(); + + b.HasIndex("UserId"); + + b.ToTable("RefreshTokens"); + }); + + modelBuilder.Entity("FiscalOS.Core.Identity.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAt") + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("FiscalOS.Core.Identity.RefreshToken", b => + { + b.HasOne("FiscalOS.Core.Identity.User", "User") + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("FiscalOS.Core.Identity.User", b => + { + b.Navigation("RefreshTokens"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.cs b/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.cs new file mode 100644 index 0000000..d4fab27 --- /dev/null +++ b/src/FiscalOS.Infra/Migrations/20260203115122_AddUserIdPropToRefreshToken.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FiscalOS.Infra.Migrations +{ + /// + public partial class AddUserIdPropToRefreshToken : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +}