Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions Infrastructure/Context/ScriptoriumDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
ο»Ώusing System;
using System.Collections.Generic;
using Infrastructure.Contexts;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal;

namespace Infrastructure.Context;

public partial class ScriptoriumDbContext : DbContext
{
public ScriptoriumDbContext()
{
}

public ScriptoriumDbContext(DbContextOptions<ScriptoriumDbContext> options)
: base(options)
{
}

public virtual DbSet<Annotation> Annotations { get; set; }

public virtual DbSet<Encyclopedium> Encyclopedia { get; set; }

public virtual DbSet<Scribe> Scribes { get; set; }

public virtual DbSet<Theme> Themes { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.UseCollation("utf8mb4_uca1400_ai_ci")
.HasCharSet("utf8mb4");

modelBuilder.Entity<Annotation>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");

entity.ToTable("Annotation");

entity.HasIndex(e => e.encyclopediaId, "Annotation_Encyclopedia_id_fk");

entity.HasIndex(e => e.themeId, "Annotation_Theme_Id_fk");

entity.Property(e => e.id).HasColumnType("int(11)");
entity.Property(e => e.contentUrl)
.HasMaxLength(255)
.HasDefaultValueSql("'notImplemented.md'");
entity.Property(e => e.encyclopediaId).HasColumnType("int(11)");
entity.Property(e => e.endPage).HasColumnType("int(11)");
entity.Property(e => e.startPage).HasColumnType("int(11)");
entity.Property(e => e.tags)
.HasMaxLength(50)
.HasDefaultValueSql("''");
entity.Property(e => e.themeId).HasColumnType("int(11)");
entity.Property(e => e.title).HasMaxLength(255);

entity.HasOne(d => d.encyclopedia).WithMany(p => p.Annotations)
.HasForeignKey(d => d.encyclopediaId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("Annotation_Encyclopedia_id_fk");

entity.HasOne(d => d.theme).WithMany(p => p.Annotations)
.HasForeignKey(d => d.themeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("Annotation_Theme_Id_fk");
});

modelBuilder.Entity<Encyclopedium>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");

entity.HasIndex(e => e.scribeId, "Encyclopedia_Scribe_id_fk");

entity.Property(e => e.id).HasColumnType("int(11)");
entity.Property(e => e.scribeId).HasMaxLength(36);
entity.Property(e => e.title).HasMaxLength(50);

entity.HasOne(d => d.scribe).WithMany(p => p.Encyclopedia)
.HasForeignKey(d => d.scribeId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("Encyclopedia_Scribe_id_fk");
});

modelBuilder.Entity<Scribe>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");

entity.ToTable("Scribe");

entity.HasIndex(e => e.username, "Scribe_username_uk").IsUnique();

entity.Property(e => e.id).HasMaxLength(36);
entity.Property(e => e.username).HasMaxLength(50);
});

modelBuilder.Entity<Theme>(entity =>
{
entity.HasKey(e => e.id).HasName("PRIMARY");

entity.ToTable("Theme");

entity.HasIndex(e => e.name, "Theme_name_uk").IsUnique();

entity.Property(e => e.id).HasColumnType("int(11)");
entity.Property(e => e.folder).HasMaxLength(50);
entity.Property(e => e.name).HasMaxLength(50);
});

OnModelCreatingPartial(modelBuilder);
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
29 changes: 29 additions & 0 deletions Infrastructure/Contexts/Annotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ο»Ώusing System;
using System.Collections.Generic;

namespace Infrastructure.Contexts;

public partial class Annotation
{
public int id { get; set; }

public string title { get; set; } = null!;

public int startPage { get; set; }

public int endPage { get; set; }

public string contentUrl { get; set; } = null!;

public string tags { get; set; } = null!;

public DateOnly date { get; set; }

public int themeId { get; set; }

public int encyclopediaId { get; set; }

public virtual Encyclopedium encyclopedia { get; set; } = null!;

public virtual Theme theme { get; set; } = null!;
}
17 changes: 17 additions & 0 deletions Infrastructure/Contexts/Encyclopedium.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ο»Ώusing System;
using System.Collections.Generic;

namespace Infrastructure.Contexts;

public partial class Encyclopedium
{
public int id { get; set; }

public string title { get; set; } = null!;

public string scribeId { get; set; } = null!;

public virtual ICollection<Annotation> Annotations { get; set; } = new List<Annotation>();

public virtual Scribe scribe { get; set; } = null!;
}
13 changes: 13 additions & 0 deletions Infrastructure/Contexts/Scribe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ο»Ώusing System;
using System.Collections.Generic;

namespace Infrastructure.Contexts;

public partial class Scribe
{
public string id { get; set; } = null!;

public string username { get; set; } = null!;

public virtual ICollection<Encyclopedium> Encyclopedia { get; set; } = new List<Encyclopedium>();
}
15 changes: 15 additions & 0 deletions Infrastructure/Contexts/Theme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ο»Ώusing System;
using System.Collections.Generic;

namespace Infrastructure.Contexts;

public partial class Theme
{
public int id { get; set; }

public string name { get; set; } = null!;

public string? folder { get; set; }

public virtual ICollection<Annotation> Annotations { get; set; } = new List<Annotation>();
}
4 changes: 4 additions & 0 deletions Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Infrastructure.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -8,6 +9,9 @@ public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
string? serverConnectionString = configuration.GetConnectionString("ScriptoriumDatabase");
services.AddDbContext<ScriptoriumDbContext>(options =>
options.UseMySql(serverConnectionString, ServerVersion.AutoDetect(serverConnectionString)));
return services;
}
}
10 changes: 10 additions & 0 deletions Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading