From ffb5e20f79e423701122842c598b694d9ea7d3ba Mon Sep 17 00:00:00 2001 From: Sandertp Date: Thu, 29 Aug 2024 12:16:01 +0200 Subject: [PATCH] Add Database Migration for RefreshToken in Users Co-authored-by: Reimar --- ...29101159_AddRefreshTokenToUser.Designer.cs | 58 +++++++++++++++++++ .../20240829101159_AddRefreshTokenToUser.cs | 51 ++++++++++++++++ API/Migrations/AppDBContextModelSnapshot.cs | 6 +- API/Models/User.cs | 2 + 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 API/Migrations/20240829101159_AddRefreshTokenToUser.Designer.cs create mode 100644 API/Migrations/20240829101159_AddRefreshTokenToUser.cs diff --git a/API/Migrations/20240829101159_AddRefreshTokenToUser.Designer.cs b/API/Migrations/20240829101159_AddRefreshTokenToUser.Designer.cs new file mode 100644 index 0000000..ec5c516 --- /dev/null +++ b/API/Migrations/20240829101159_AddRefreshTokenToUser.Designer.cs @@ -0,0 +1,58 @@ +// +using System; +using API; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace API.Migrations +{ + [DbContext(typeof(AppDBContext))] + [Migration("20240829101159_AddRefreshTokenToUser")] + partial class AddRefreshTokenToUser + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); + + modelBuilder.Entity("API.Models.User", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("HashedPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefreshToken") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefreshTokenExpiresAt") + .HasColumnType("TEXT"); + + b.Property("UpdatedAt") + .HasColumnType("TEXT"); + + b.Property("Username") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Migrations/20240829101159_AddRefreshTokenToUser.cs b/API/Migrations/20240829101159_AddRefreshTokenToUser.cs new file mode 100644 index 0000000..5e4ecee --- /dev/null +++ b/API/Migrations/20240829101159_AddRefreshTokenToUser.cs @@ -0,0 +1,51 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Migrations +{ + /// + public partial class AddRefreshTokenToUser : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Password", + table: "Users"); + + migrationBuilder.AddColumn( + name: "RefreshToken", + table: "Users", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "RefreshTokenExpiresAt", + table: "Users", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "RefreshToken", + table: "Users"); + + migrationBuilder.DropColumn( + name: "RefreshTokenExpiresAt", + table: "Users"); + + migrationBuilder.AddColumn( + name: "Password", + table: "Users", + type: "TEXT", + nullable: true); + } + } +} diff --git a/API/Migrations/AppDBContextModelSnapshot.cs b/API/Migrations/AppDBContextModelSnapshot.cs index 19b280c..9bb3e04 100644 --- a/API/Migrations/AppDBContextModelSnapshot.cs +++ b/API/Migrations/AppDBContextModelSnapshot.cs @@ -32,7 +32,11 @@ namespace API.Migrations .IsRequired() .HasColumnType("TEXT"); - b.Property("Password") + b.Property("RefreshToken") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefreshTokenExpiresAt") .HasColumnType("TEXT"); b.Property("UpdatedAt") diff --git a/API/Models/User.cs b/API/Models/User.cs index 99072d0..fcaaa30 100644 --- a/API/Models/User.cs +++ b/API/Models/User.cs @@ -7,6 +7,8 @@ public class User : BaseModel public string? Email { get; set; } public string? Username { get; set; } public string HashedPassword { get; set; } + public string RefreshToken { get; set; } + public DateTime RefreshTokenExpiresAt { get; set; } } public class UserDTO