Updated lots of stuff, got multi scrape working, need to test not-nullable chapter novel ids with our current model, now supports sqlite and postgres concurrently (and easy add more), need to get it deployed/do auth
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
using System.Reflection;
|
||||
using DBConnection.ModelBuilders;
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Seeders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection;
|
||||
namespace DBConnection.Contexts;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
public abstract class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<Novel> Novels { get; set; }
|
||||
public DbSet<Chapter> Chapters { get; set; }
|
||||
@@ -14,6 +15,8 @@ public class AppDbContext : DbContext
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Tag> Tags { get; set; }
|
||||
public DbSet<UserNovel> UserNovels { get; set; }
|
||||
protected IConfiguration Configuration { get; set; }
|
||||
protected abstract string ConnectionStringName { get; }
|
||||
|
||||
private readonly IEnumerable<ISeeder> _seeders =
|
||||
from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
@@ -25,8 +28,9 @@ public class AppDbContext : DbContext
|
||||
where t.IsClass && (t.Namespace?.Contains(nameof(DBConnection.ModelBuilders)) ?? false) && typeof(IModelBuilder).IsAssignableFrom(t)
|
||||
select (IModelBuilder) Activator.CreateInstance(t);
|
||||
|
||||
public AppDbContext(DbContextOptions options) : base(options)
|
||||
protected AppDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
@@ -64,5 +68,8 @@ public class AppDbContext : DbContext
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
UseSqlConnection(optionsBuilder, Configuration.GetConnectionString(ConnectionStringName));
|
||||
}
|
||||
|
||||
protected abstract void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString);
|
||||
}
|
||||
21
DBConnection/Contexts/PostgresSqlAppDbContext.cs
Normal file
21
DBConnection/Contexts/PostgresSqlAppDbContext.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace DBConnection.Contexts;
|
||||
|
||||
/// <summary>
|
||||
/// Pulls connection string from 'PostgresSql' and selected with provider 'PostgresSql'
|
||||
/// </summary>
|
||||
public class PostgresSqlAppDbContext : AppDbContext
|
||||
{
|
||||
public PostgresSqlAppDbContext(DbContextOptions options, IConfiguration configuration) : base(options, configuration)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ConnectionStringName => "PostgresSql";
|
||||
|
||||
protected override void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString)
|
||||
{
|
||||
builder.UseNpgsql(connectionString);
|
||||
}
|
||||
}
|
||||
21
DBConnection/Contexts/SqliteAppDbContext.cs
Normal file
21
DBConnection/Contexts/SqliteAppDbContext.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace DBConnection.Contexts;
|
||||
|
||||
/// <summary>
|
||||
/// Pulls connection string from 'Sqlite' and selected with provider 'Sqlite'
|
||||
/// </summary>
|
||||
public class SqliteAppDbContext : AppDbContext
|
||||
{
|
||||
public SqliteAppDbContext(DbContextOptions options, IConfiguration configuration) : base(options, configuration)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected override string ConnectionStringName => "Sqlite";
|
||||
protected override void UseSqlConnection(DbContextOptionsBuilder builder, string connectionString)
|
||||
{
|
||||
builder.UseSqlite(connectionString);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces" />
|
||||
<Folder Include="Migrations\PostgresSql" />
|
||||
<Folder Include="Migrations\Sqlite" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Treestar.Shared\Treestar.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace DBConnection.Enums;
|
||||
|
||||
public enum NovelStatus
|
||||
{
|
||||
InProgress,
|
||||
Completed,
|
||||
Hiatus,
|
||||
Unknown
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -15,11 +16,22 @@ public static class BuilderExtensions
|
||||
/// <param name="config">configuration</param>
|
||||
public static void AddDbServices(this IServiceCollection collection, IConfiguration config)
|
||||
{
|
||||
string dbConnectionString = config.GetConnectionString("DefaultConnection");
|
||||
collection.AddDbContext<AppDbContext>(opt =>
|
||||
{
|
||||
opt.UseSqlite(dbConnectionString);
|
||||
});
|
||||
// Add appropriate DbContext
|
||||
// Contexts are linked to providers by trimming the 'AppDbContext' portion of their name.
|
||||
// So 'PostgresSqlAppDbContext' is selected with provider 'PostgresSql'
|
||||
var providerTypes = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => (t.Namespace?.Contains(nameof(Contexts)) ?? false) && typeof(AppDbContext).IsAssignableFrom(t) && !t.IsAbstract && t.Name.EndsWith(nameof(AppDbContext)));
|
||||
var providers = providerTypes.ToDictionary(t => t.Name.Replace(nameof(AppDbContext), ""), t => t);
|
||||
var selectedProvider = config["DatabaseProvider"];
|
||||
|
||||
//add dboptions
|
||||
collection.AddSingleton(new DbContextOptions<AppDbContext>());
|
||||
collection.AddSingleton<DbContextOptions>(p => p.GetRequiredService<DbContextOptions<AppDbContext>>());
|
||||
|
||||
// add our provider dbcontext
|
||||
collection.AddScoped(typeof(AppDbContext), providers[selectedProvider]);
|
||||
|
||||
// Add db repositories
|
||||
Type[] repositories = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.IsClass && !t.IsAbstract && (t.Namespace?.Contains(nameof(DBConnection.Repositories)) ?? false) && typeof(IRepository).IsAssignableFrom(t)).ToArray();
|
||||
foreach (var repo in repositories)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class AddLastContentFetch : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
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: "LastContentFetch",
|
||||
table: "Chapters");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class makesomechapterfieldsoptional : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DateUpdated",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DatePosted",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DateUpdated",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DatePosted",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class addidfornovels : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "Guid",
|
||||
table: "Novels",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Guid",
|
||||
table: "Novels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,100 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.PostgresSql
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715030913_Initial")]
|
||||
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||
[Migration("20220716211121_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
@@ -79,29 +103,35 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
@@ -110,53 +140,55 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
@@ -167,44 +199,46 @@ namespace DBConnection.Migrations
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -215,32 +249,17 @@ namespace DBConnection.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
200
DBConnection/Migrations/PostgresSql/20220716211121_Initial.cs
Normal file
200
DBConnection/Migrations/PostgresSql/20220716211121_Initial.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations.PostgresSql
|
||||
{
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Authors",
|
||||
columns: table => new
|
||||
{
|
||||
Url = table.Column<string>(type: "text", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Authors", x => x.Url);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Tags",
|
||||
columns: table => new
|
||||
{
|
||||
TagValue = table.Column<string>(type: "text", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Tags", x => x.TagValue);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Email = table.Column<string>(type: "text", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Novels",
|
||||
columns: table => new
|
||||
{
|
||||
Url = table.Column<string>(type: "text", nullable: false),
|
||||
Guid = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Title = table.Column<string>(type: "text", nullable: false),
|
||||
AuthorUrl = table.Column<string>(type: "text", nullable: true),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
LastUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DatePosted = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Novels", x => x.Url);
|
||||
table.ForeignKey(
|
||||
name: "FK_Novels_Authors_AuthorUrl",
|
||||
column: x => x.AuthorUrl,
|
||||
principalTable: "Authors",
|
||||
principalColumn: "Url");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Chapters",
|
||||
columns: table => new
|
||||
{
|
||||
Url = table.Column<string>(type: "text", nullable: false),
|
||||
ChapterNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Content = table.Column<string>(type: "text", nullable: true),
|
||||
RawContent = table.Column<string>(type: "text", nullable: true),
|
||||
DatePosted = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
LastContentFetch = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Chapters", x => x.Url);
|
||||
table.ForeignKey(
|
||||
name: "FK_Chapters_Novels_NovelUrl",
|
||||
column: x => x.NovelUrl,
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Url",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NovelTag",
|
||||
columns: table => new
|
||||
{
|
||||
NovelsUrl = table.Column<string>(type: "text", nullable: false),
|
||||
TagsTagValue = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NovelTag", x => new { x.NovelsUrl, x.TagsTagValue });
|
||||
table.ForeignKey(
|
||||
name: "FK_NovelTag_Novels_NovelsUrl",
|
||||
column: x => x.NovelsUrl,
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Url",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_NovelTag_Tags_TagsTagValue",
|
||||
column: x => x.TagsTagValue,
|
||||
principalTable: "Tags",
|
||||
principalColumn: "TagValue",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "UserNovels",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<int>(type: "integer", nullable: false),
|
||||
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||
LastChapterRead = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_UserNovels", x => new { x.NovelUrl, x.UserId });
|
||||
table.ForeignKey(
|
||||
name: "FK_UserNovels_Novels_NovelUrl",
|
||||
column: x => x.NovelUrl,
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Url",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_UserNovels_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Chapters_NovelUrl",
|
||||
table: "Chapters",
|
||||
column: "NovelUrl");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Novels_AuthorUrl",
|
||||
table: "Novels",
|
||||
column: "AuthorUrl");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NovelTag_TagsTagValue",
|
||||
table: "NovelTag",
|
||||
column: "TagsTagValue");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserNovels_UserId",
|
||||
table: "UserNovels",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Chapters");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "NovelTag");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "UserNovels");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Tags");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Novels");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Authors");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,100 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.PostgresSql
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715040739_AddLastContentFetch")]
|
||||
partial class AddLastContentFetch
|
||||
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||
[Migration("20220716211513_Add index on novel guid")]
|
||||
partial class Addindexonnovelguid
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("LastContentFetch")
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
@@ -82,84 +103,94 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.HasIndex("Guid");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("INTEGER");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
@@ -170,44 +201,46 @@ namespace DBConnection.Migrations
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -218,32 +251,17 @@ namespace DBConnection.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations.PostgresSql
|
||||
{
|
||||
public partial class Addindexonnovelguid : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Novels_Guid",
|
||||
table: "Novels",
|
||||
column: "Guid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Novels_Guid",
|
||||
table: "Novels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations.PostgresSql
|
||||
{
|
||||
[DbContext(typeof(PostgresSqlAppDbContext))]
|
||||
partial class PostgresSqlAppDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.HasIndex("Guid");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Novel");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@@ -8,18 +8,33 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.Sqlite
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715143230_add id for novels")]
|
||||
partial class addidfornovels
|
||||
[DbContext(typeof(SqliteAppDbContext))]
|
||||
[Migration("20220716210907_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -39,7 +54,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -70,6 +85,7 @@ namespace DBConnection.Migrations
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
@@ -82,7 +98,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -100,12 +116,14 @@ namespace DBConnection.Migrations
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -117,7 +135,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -133,7 +151,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -154,7 +172,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -174,44 +192,46 @@ namespace DBConnection.Migrations
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -222,32 +242,17 @@ namespace DBConnection.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.Sqlite
|
||||
{
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
@@ -56,8 +56,10 @@ namespace DBConnection.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Url = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Guid = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Title = table.Column<string>(type: "TEXT", nullable: false),
|
||||
AuthorUrl = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
LastUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
@@ -82,9 +84,10 @@ namespace DBConnection.Migrations
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Content = table.Column<string>(type: "TEXT", nullable: true),
|
||||
RawContent = table.Column<string>(type: "TEXT", nullable: true),
|
||||
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
DateUpdated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
NovelUrl = table.Column<string>(type: "TEXT", nullable: true),
|
||||
DatePosted = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
DateUpdated = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
LastContentFetch = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
NovelUrl = table.Column<string>(type: "TEXT", nullable: false),
|
||||
DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
DateModified = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
},
|
||||
@@ -95,7 +98,8 @@ namespace DBConnection.Migrations
|
||||
name: "FK_Chapters_Novels_NovelUrl",
|
||||
column: x => x.NovelUrl,
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Url");
|
||||
principalColumn: "Url",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@@ -1,6 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@@ -8,18 +8,33 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.Sqlite
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715135707_make some chapter fields optional")]
|
||||
partial class makesomechapterfieldsoptional
|
||||
[DbContext(typeof(SqliteAppDbContext))]
|
||||
[Migration("20220716211435_Add index on novel guid")]
|
||||
partial class Addindexonnovelguid
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -39,7 +54,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -70,6 +85,7 @@ namespace DBConnection.Migrations
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
@@ -82,7 +98,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -99,9 +115,15 @@ namespace DBConnection.Migrations
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -110,10 +132,12 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.HasIndex("Guid");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -129,7 +153,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -150,7 +174,7 @@ namespace DBConnection.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -170,44 +194,46 @@ namespace DBConnection.Migrations
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -218,32 +244,17 @@ namespace DBConnection.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations.Sqlite
|
||||
{
|
||||
public partial class Addindexonnovelguid : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Novels_Guid",
|
||||
table: "Novels",
|
||||
column: "Guid");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Novels_Guid",
|
||||
table: "Novels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,38 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using DBConnection.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
namespace DBConnection.Migrations.Sqlite
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
partial class AppDbContextModelSnapshot : ModelSnapshot
|
||||
[DbContext(typeof(SqliteAppDbContext))]
|
||||
partial class SqliteAppDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -34,10 +49,10 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors", (string)null);
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -68,6 +83,7 @@ namespace DBConnection.Migrations
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
@@ -77,10 +93,10 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters", (string)null);
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -98,12 +114,14 @@ namespace DBConnection.Migrations
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -112,10 +130,12 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.ToTable("Novels", (string)null);
|
||||
b.HasIndex("Guid");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -128,10 +148,10 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags", (string)null);
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -149,10 +169,10 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users", (string)null);
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -167,49 +187,51 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels", (string)null);
|
||||
b.ToTable("UserNovels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag", (string)null);
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -220,32 +242,17 @@ namespace DBConnection.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
using DBConnection.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.ModelBuilders;
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class Author : BaseEntity
|
||||
{
|
||||
[Key]
|
||||
public string Url { get; set; }
|
||||
public string Name { get; set; }
|
||||
[JsonIgnore]
|
||||
public List<Novel> Novels { get; set; }
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public abstract class BaseEntity
|
||||
{
|
||||
public DateTime DateCreated { get; set; }
|
||||
public DateTime DateModified { get; set; }
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class Chapter : BaseEntity
|
||||
{
|
||||
public int ChapterNumber { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Content { get; set; }
|
||||
public string? RawContent { get; set; }
|
||||
[Key]
|
||||
public string Url { get; set; }
|
||||
public DateTime? DatePosted { get; set; }
|
||||
public DateTime? DateUpdated { get; set; }
|
||||
public DateTime? LastContentFetch { get; set; }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class Novel : BaseEntity
|
||||
{
|
||||
[Key]
|
||||
public string Url { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Author Author { get; set; }
|
||||
public List<Tag> Tags { get; set; }
|
||||
public List<Chapter> Chapters { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
public DateTime DatePosted { get; set; }
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class Tag : BaseEntity
|
||||
{
|
||||
[Key]
|
||||
public string TagValue { get; set; }
|
||||
[JsonIgnore]
|
||||
public List<Novel> Novels { get; set; }
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class User : BaseEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public List<UserNovel> WatchedNovels { get; set; }
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
public class UserNovel
|
||||
{
|
||||
[JsonIgnore]
|
||||
public int UserId { get; set; }
|
||||
public string NovelUrl { get; set; }
|
||||
public Novel Novel { get; set; }
|
||||
public User User { get; set; }
|
||||
public int LastChapterRead { get; set; }
|
||||
}
|
||||
13
DBConnection/Readme.md
Normal file
13
DBConnection/Readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# DBConnection
|
||||
## Providers
|
||||
Currently AppDbContext can support:
|
||||
* Sqlite (default)
|
||||
* PostgresSql
|
||||
|
||||
The startup project should specify a 'DatabaseProvider' configuration key and provide an appropriate connection string
|
||||
## Repositories
|
||||
Repositories added into the DBConnection.Repositories namespace and assignable (implementing) IRepository will be dependency injected.
|
||||
|
||||
Repositories extending a non-generic interface that also implements IRepository (or some descendant interface) will be DI'd as an implementation of that interface.
|
||||
|
||||
As an example, AuthorRepository implements IAuthorRepository which implements IRepository<Author> which implements IRepository. Therefore, Author will get added as an implementation of IAuthorRepository.
|
||||
@@ -1,6 +1,7 @@
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Reflection;
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NuGet.Configuration;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
@@ -30,7 +31,22 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
||||
return entity;
|
||||
}
|
||||
|
||||
public virtual async Task<TEntityType> Upsert(TEntityType entity)
|
||||
public virtual async Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true)
|
||||
{
|
||||
var newEntities = new List<TEntityType>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
newEntities.Add(await Upsert(entity, false));
|
||||
}
|
||||
|
||||
if (saveAfter)
|
||||
{
|
||||
await DbContext.SaveChangesAsync();
|
||||
}
|
||||
return newEntities;
|
||||
}
|
||||
|
||||
public virtual async Task<TEntityType> Upsert(TEntityType entity, bool saveAfter=true)
|
||||
{
|
||||
bool exists = await DbContext.Set<TEntityType>().ContainsAsync(entity);
|
||||
if (!exists)
|
||||
@@ -40,10 +56,16 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
||||
else
|
||||
{
|
||||
var dbEntry = await GetIncluded(entity);
|
||||
DbContext.Entry(dbEntry).CurrentValues.SetValues(entity);
|
||||
entity.DateCreated = dbEntry.DateCreated;
|
||||
var entry = DbContext.Entry(dbEntry);
|
||||
entry.CurrentValues.SetValues(entity);
|
||||
entity = dbEntry;
|
||||
}
|
||||
|
||||
await DbContext.SaveChangesAsync();
|
||||
if (saveAfter)
|
||||
{
|
||||
await DbContext.SaveChangesAsync();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
18
DBConnection/Repositories/ChapterRepository.cs
Normal file
18
DBConnection/Repositories/ChapterRepository.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
public class ChapterRepository : BaseRepository<Chapter>, IChapterRepository
|
||||
{
|
||||
public ChapterRepository(AppDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
}
|
||||
|
||||
protected override IQueryable<Chapter> GetAllIncludedQueryable()
|
||||
{
|
||||
return DbContext.Chapters.AsQueryable();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using DBConnection.Models;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
public interface IChapterRepository : IRepository<Chapter>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using DBConnection.Models;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DBConnection.Models;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
@@ -10,9 +10,10 @@ public interface IRepository
|
||||
public interface IRepository<TEntityType> : IRepository where TEntityType : BaseEntity
|
||||
{
|
||||
TEntityType Delete(TEntityType entity);
|
||||
Task<TEntityType> Upsert(TEntityType entity);
|
||||
Task<TEntityType> Upsert(TEntityType entity, bool saveAfter=true);
|
||||
Task<TEntityType?> GetIncluded(TEntityType entity);
|
||||
Task<TEntityType?> GetIncluded(Func<TEntityType, bool> predicate);
|
||||
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
|
||||
Task<IEnumerable<TEntityType>> GetAllIncluded();
|
||||
Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true);
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using DBConnection.Models;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
public interface ITagRepository : IRepository<Tag>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
@@ -8,51 +9,44 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
|
||||
{
|
||||
private readonly IAuthorRepository _authorRepository;
|
||||
private readonly ITagRepository _tagRepository;
|
||||
public NovelRepository(AppDbContext dbContext, IAuthorRepository authorRepository, ITagRepository tagRepository) : base(dbContext)
|
||||
private readonly IChapterRepository _chapterRepository;
|
||||
public NovelRepository(AppDbContext dbContext, IAuthorRepository authorRepository, ITagRepository tagRepository, IChapterRepository chapterRepository) : base(dbContext)
|
||||
{
|
||||
_authorRepository = authorRepository;
|
||||
_tagRepository = tagRepository;
|
||||
_chapterRepository = chapterRepository;
|
||||
}
|
||||
|
||||
public override async Task<Novel> Upsert(Novel entity)
|
||||
public override async Task<Novel> Upsert(Novel entity, bool saveAfter=true)
|
||||
{
|
||||
var dbEntity = await GetIncluded(entity) ?? entity;
|
||||
// Author
|
||||
dbEntity.Author = await _authorRepository.GetIncluded(entity.Author) ?? entity.Author;
|
||||
if (entity.Author != null)
|
||||
{
|
||||
entity.Author = await _authorRepository.Upsert(entity.Author, saveAfter);
|
||||
}
|
||||
|
||||
//Tags
|
||||
List<Tag> newTags = new List<Tag>();
|
||||
foreach (var tag in entity.Tags)
|
||||
{
|
||||
newTags.Add(await _tagRepository.GetIncluded(tag) ?? tag);
|
||||
}
|
||||
dbEntity.Tags.Clear();
|
||||
dbEntity.Tags = newTags;
|
||||
var newTags = await _tagRepository.UpsertMany(entity.Tags, false);
|
||||
entity.Tags.Clear();
|
||||
entity.Tags = newTags.ToList();
|
||||
//chapters
|
||||
var newChapters = new List<Chapter>();
|
||||
foreach (var chapter in entity.Chapters.ToList())
|
||||
{
|
||||
var existingChapter = await DbContext.Chapters.FindAsync(chapter.Url);
|
||||
if (existingChapter == null)
|
||||
{
|
||||
newChapters.Add(chapter);
|
||||
}
|
||||
else
|
||||
{
|
||||
existingChapter.Name = chapter.Name;
|
||||
existingChapter.DateUpdated = chapter.DateUpdated;
|
||||
newChapters.Add(existingChapter);
|
||||
}
|
||||
}
|
||||
dbEntity.Chapters.Clear();
|
||||
dbEntity.Chapters = newChapters;
|
||||
var newChapters = await _chapterRepository.UpsertMany(entity.Chapters, false);
|
||||
entity.Chapters.Clear();
|
||||
entity.Chapters = newChapters.ToList();
|
||||
// update in db
|
||||
var dbEntity = await GetIncluded(entity) ?? entity;
|
||||
entity.Guid = dbEntity.Guid;
|
||||
DbContext.Entry(dbEntity).CurrentValues.SetValues(entity);
|
||||
if (DbContext.Entry(dbEntity).State == EntityState.Detached)
|
||||
{
|
||||
dbEntity.Guid = Guid.NewGuid();
|
||||
DbContext.Add(dbEntity);
|
||||
}
|
||||
|
||||
await DbContext.SaveChangesAsync();
|
||||
if (saveAfter)
|
||||
{
|
||||
await DbContext.SaveChangesAsync();
|
||||
}
|
||||
return dbEntity;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using DBConnection.Models;
|
||||
using DBConnection.Contexts;
|
||||
using DBConnection.Repositories.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Treestar.Shared.Models.DBDomain;
|
||||
|
||||
namespace DBConnection.Repositories;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user