From 3a1a7138c5c1d50e779646902ec4d53700305acb Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 2 Feb 2026 07:00:28 -0600 Subject: [PATCH] feat(infra): update refresh token model --- src/FiscalOS.Infra/Data/AppDbContext.cs | 8 +- ...2125635_AddPropsToRefreshToken.Designer.cs | 95 +++++++++++++++++++ .../20260202125635_AddPropsToRefreshToken.cs | 41 ++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 7 ++ 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.Designer.cs create mode 100644 src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.cs diff --git a/src/FiscalOS.Infra/Data/AppDbContext.cs b/src/FiscalOS.Infra/Data/AppDbContext.cs index acc250d..bd0c681 100644 --- a/src/FiscalOS.Infra/Data/AppDbContext.cs +++ b/src/FiscalOS.Infra/Data/AppDbContext.cs @@ -36,13 +36,13 @@ public sealed class AppDbContext(IOptions ctxOptions) : DbC foreach (var entityType in entityTypes) { modelBuilder.Entity(entityType.ClrType) - .HasKey(nameof(Entity.Id)); + .HasKey(nameof(Entity.Id)); modelBuilder.Entity(entityType.ClrType) - .Property(nameof(Entity.CreatedAt)); + .Property(nameof(Entity.CreatedAt)); modelBuilder.Entity(entityType.ClrType) - .Property(nameof(Entity.UpdatedAt)); + .Property(nameof(Entity.UpdatedAt)); } modelBuilder.Entity(static eb => @@ -59,6 +59,8 @@ public sealed class AppDbContext(IOptions ctxOptions) : DbC modelBuilder.Entity(static eb => { eb.Property(static t => t.Id); + eb.Property(static t => t.ExpiresAt); + eb.Property(static t => t.Token); }); } } \ No newline at end of file diff --git a/src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.Designer.cs b/src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.Designer.cs new file mode 100644 index 0000000..7445ddb --- /dev/null +++ b/src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.Designer.cs @@ -0,0 +1,95 @@ +// +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("20260202125635_AddPropsToRefreshToken")] + partial class AddPropsToRefreshToken + { + /// + 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("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.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/20260202125635_AddPropsToRefreshToken.cs b/src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.cs new file mode 100644 index 0000000..e7428b8 --- /dev/null +++ b/src/FiscalOS.Infra/Migrations/20260202125635_AddPropsToRefreshToken.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FiscalOS.Infra.Migrations +{ + /// + public partial class AddPropsToRefreshToken : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ExpiresAt", + table: "RefreshTokens", + type: "TEXT", + nullable: false, + defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); + + migrationBuilder.AddColumn( + name: "Token", + table: "RefreshTokens", + type: "TEXT", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ExpiresAt", + table: "RefreshTokens"); + + migrationBuilder.DropColumn( + name: "Token", + table: "RefreshTokens"); + } + } +} diff --git a/src/FiscalOS.Infra/Migrations/AppDbContextModelSnapshot.cs b/src/FiscalOS.Infra/Migrations/AppDbContextModelSnapshot.cs index 1595455..0a74549 100644 --- a/src/FiscalOS.Infra/Migrations/AppDbContextModelSnapshot.cs +++ b/src/FiscalOS.Infra/Migrations/AppDbContextModelSnapshot.cs @@ -26,6 +26,13 @@ namespace FiscalOS.Infra.Migrations b.Property("CreatedAt") .HasColumnType("TEXT"); + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Token") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("UpdatedAt") .HasColumnType("TEXT");