This commit is contained in:
6d486f49
2026-08-17 00:45:08 -04:00
parent 3a2f112a73
commit 1d6207fbfe
154 changed files with 126007 additions and 47385 deletions
+33
View File
@@ -0,0 +1,33 @@
using API.Models;
using Microsoft.EntityFrameworkCore;
using Model;
namespace API.Data;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; } = default!;
public DbSet<CardNote> CardNotes { get; set; } = default!;
public DbSet<UserDeck> UserDecks { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(b => { b.HasKey(u => u.Username); });
modelBuilder.Entity<CardNote>(b => { b.HasKey(n => new { n.Username, n.CardName }); });
modelBuilder.Entity<UserDeck>(b =>
{
b.HasKey(d => d.Id);
if (Database.IsNpgsql())
{
b.Property(d => d.Cards).HasColumnType("jsonb");
b.Property(d => d.Divers).HasColumnType("jsonb");
}
});
}
}
+36
View File
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Npgsql;
namespace API.Data;
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
var envPassword = Environment.GetEnvironmentVariable("PostgreSQL_Password")
?? (OperatingSystem.IsWindows()
? Environment.GetEnvironmentVariable("PostgreSQL_Password",
EnvironmentVariableTarget.User)
: null)
?? (OperatingSystem.IsWindows()
? Environment.GetEnvironmentVariable("PostgreSQL_Password",
EnvironmentVariableTarget.Machine)
: null)
?? Environment.GetEnvironmentVariable("POSTGRESQL_PASSWORD")
?? Environment.GetEnvironmentVariable("POSTGRES_PASSWORD");
var csb = new NpgsqlConnectionStringBuilder
{
Host = "localhost",
Database = "chrono",
Username = "postgres",
Password = envPassword
};
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseNpgsql(csb.ConnectionString)
.Options;
return new AppDbContext(options);
}
}