auth changes

This commit is contained in:
2024-03-28 19:17:46 +01:00
Unverified
parent 0d9a42dd24
commit fcca2119a5
45 changed files with 6588 additions and 55 deletions

View File

@@ -37,6 +37,7 @@ namespace WatchIt.Database
// Account
public virtual DbSet<Account> Accounts { get; set; }
public virtual DbSet<AccountProfilePicture> AccountProfilePictures { get; set; }
public virtual DbSet<AccountRefreshToken> AccountRefreshTokens { get; set; }
// Media
public virtual DbSet<Media> Media { get; set; }
@@ -87,6 +88,7 @@ namespace WatchIt.Database
// Account
EntityBuilder.Build<Account>(modelBuilder);
EntityBuilder.Build<AccountProfilePicture>(modelBuilder);
EntityBuilder.Build<AccountRefreshToken>(modelBuilder);
// Media
EntityBuilder.Build<Media>(modelBuilder);

View File

@@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class _0003_GenderNotRequiredAndDefaultNotAdmin : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Accounts_Genders_GenderId",
table: "Accounts");
migrationBuilder.AlterColumn<bool>(
name: "IsAdmin",
table: "Accounts",
type: "boolean",
nullable: false,
defaultValue: false,
oldClrType: typeof(bool),
oldType: "boolean");
migrationBuilder.AlterColumn<short>(
name: "GenderId",
table: "Accounts",
type: "smallint",
nullable: true,
oldClrType: typeof(short),
oldType: "smallint");
migrationBuilder.AddForeignKey(
name: "FK_Accounts_Genders_GenderId",
table: "Accounts",
column: "GenderId",
principalTable: "Genders",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Accounts_Genders_GenderId",
table: "Accounts");
migrationBuilder.AlterColumn<bool>(
name: "IsAdmin",
table: "Accounts",
type: "boolean",
nullable: false,
oldClrType: typeof(bool),
oldType: "boolean",
oldDefaultValue: false);
migrationBuilder.AlterColumn<short>(
name: "GenderId",
table: "Accounts",
type: "smallint",
nullable: false,
defaultValue: (short)0,
oldClrType: typeof(short),
oldType: "smallint",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Accounts_Genders_GenderId",
table: "Accounts",
column: "GenderId",
principalTable: "Genders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class _0004_AccountDescriptionNullable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "Accounts",
type: "character varying(1000)",
maxLength: 1000,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(1000)",
oldMaxLength: 1000);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "Accounts",
type: "character varying(1000)",
maxLength: 1000,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(1000)",
oldMaxLength: 1000,
oldNullable: true);
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class _0005_AccountRefreshTokensAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AccountRefreshTokens",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
AccountId = table.Column<long>(type: "bigint", nullable: false),
Lifetime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AccountRefreshTokens", x => x.Id);
table.ForeignKey(
name: "FK_AccountRefreshTokens_Accounts_AccountId",
column: x => x.AccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AccountRefreshTokens_AccountId",
table: "AccountRefreshTokens",
column: "AccountId");
migrationBuilder.CreateIndex(
name: "IX_AccountRefreshTokens_Id",
table: "AccountRefreshTokens",
column: "Id",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AccountRefreshTokens");
}
}
}

View File

@@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WatchIt.Database.Migrations
{
/// <inheritdoc />
public partial class _0006_AccountRefreshTokenChanges : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Lifetime",
table: "AccountRefreshTokens",
newName: "ExpirationDate");
migrationBuilder.AddColumn<bool>(
name: "IsExtendable",
table: "AccountRefreshTokens",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsExtendable",
table: "AccountRefreshTokens");
migrationBuilder.RenameColumn(
name: "ExpirationDate",
table: "AccountRefreshTokens",
newName: "Lifetime");
}
}
}

View File

@@ -39,7 +39,6 @@ namespace WatchIt.Database.Migrations
.HasDefaultValueSql("now()");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");
@@ -48,11 +47,13 @@ namespace WatchIt.Database.Migrations
.HasMaxLength(320)
.HasColumnType("character varying(320)");
b.Property<short>("GenderId")
b.Property<short?>("GenderId")
.HasColumnType("smallint");
b.Property<bool>("IsAdmin")
.HasColumnType("boolean");
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false);
b.Property<DateTime>("LastActive")
.ValueGeneratedOnAdd()
@@ -126,6 +127,31 @@ namespace WatchIt.Database.Migrations
b.ToTable("AccountProfilePictures");
});
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountRefreshToken", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<long>("AccountId")
.HasColumnType("bigint");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsExtendable")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("AccountId");
b.HasIndex("Id")
.IsUnique();
b.ToTable("AccountRefreshTokens");
});
modelBuilder.Entity("WatchIt.Database.Model.Common.Country", b =>
{
b.Property<short>("Id")
@@ -891,9 +917,7 @@ namespace WatchIt.Database.Migrations
b.HasOne("WatchIt.Database.Model.Common.Gender", "Gender")
.WithMany()
.HasForeignKey("GenderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("GenderId");
b.HasOne("WatchIt.Database.Model.Account.AccountProfilePicture", "ProfilePicture")
.WithOne("Account")
@@ -906,6 +930,17 @@ namespace WatchIt.Database.Migrations
b.Navigation("ProfilePicture");
});
modelBuilder.Entity("WatchIt.Database.Model.Account.AccountRefreshToken", b =>
{
b.HasOne("WatchIt.Database.Model.Account.Account", "Account")
.WithMany("AccountRefreshTokens")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Account");
});
modelBuilder.Entity("WatchIt.Database.Model.Media.Media", b =>
{
b.HasOne("WatchIt.Database.Model.Media.MediaMovie", null)
@@ -1188,6 +1223,8 @@ namespace WatchIt.Database.Migrations
modelBuilder.Entity("WatchIt.Database.Model.Account.Account", b =>
{
b.Navigation("AccountRefreshTokens");
b.Navigation("RatingMedia");
b.Navigation("RatingMediaSeriesEpisode");