Skip to content

Commit

Permalink
Add Account Recovery Model (#173)
Browse files Browse the repository at this point in the history
* Add model

* Remove erroneous fields and field inits
  • Loading branch information
zysim authored Aug 21, 2023
1 parent d237e53 commit 51a5e30
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions LeaderboardBackend/Migrations/20230806090228_AddAccountRecovery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;

#nullable disable

namespace LeaderboardBackend.Migrations
{
/// <inheritdoc />
public partial class AddAccountRecovery : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "account_recoveries",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
user_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
used_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
expires_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_account_recoveries", x => x.id);
table.ForeignKey(
name: "fk_account_recoveries_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "ix_account_recoveries_user_id",
table: "account_recoveries",
column: "user_id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "account_recoveries");
}
}
}
49 changes: 49 additions & 0 deletions LeaderboardBackend/Migrations/ApplicationContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ protected override void BuildModel(ModelBuilder modelBuilder)
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "user_role", new[] { "registered", "confirmed", "administrator", "banned" });
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("LeaderboardBackend.Models.Entities.AccountRecovery", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<Instant>("ExpiresAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expires_at");
b.Property<Instant?>("UsedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("used_at");
b.Property<Guid>("UserId")
.HasColumnType("uuid")
.HasColumnName("user_id");
b.HasKey("Id")
.HasName("pk_account_recoveries");
b.HasIndex("UserId")
.HasDatabaseName("ix_account_recoveries_user_id");
b.ToTable("account_recoveries", (string)null);
});

modelBuilder.Entity("LeaderboardBackend.Models.Entities.Category", b =>
{
b.Property<long>("Id")
Expand Down Expand Up @@ -178,6 +210,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
});
});

modelBuilder.Entity("LeaderboardBackend.Models.Entities.AccountRecovery", b =>
{
b.HasOne("LeaderboardBackend.Models.Entities.User", "User")
.WithMany("AccountRecoveries")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_account_recoveries_users_user_id");
b.Navigation("User");
});

modelBuilder.Entity("LeaderboardBackend.Models.Entities.Category", b =>
{
b.HasOne("LeaderboardBackend.Models.Entities.Leaderboard", "Leaderboard")
Expand Down Expand Up @@ -206,6 +250,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
b.Navigation("Categories");
});

modelBuilder.Entity("LeaderboardBackend.Models.Entities.User", b =>
{
b.Navigation("AccountRecoveries");
});
#pragma warning restore 612, 618
}
}
Expand Down
Loading

0 comments on commit 51a5e30

Please sign in to comment.