#65 db migration and import from mysql code

This commit is contained in:
Hamid Reza Mohammadi 2021-02-04 18:19:12 +03:30
parent c4fcaf7e76
commit 7a21697401
6 changed files with 2289 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace RMuseum.Migrations
{
public partial class GanjoorComments : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "GanjoorComments",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PoemId = table.Column<int>(nullable: false),
UserId = table.Column<Guid>(nullable: true),
AuthorName = table.Column<string>(nullable: true),
AuthorEmail = table.Column<string>(nullable: true),
AuthorUrl = table.Column<string>(nullable: true),
AuthorIpAddress = table.Column<string>(nullable: true),
CommentDate = table.Column<DateTime>(nullable: false),
HtmlComment = table.Column<string>(nullable: true),
InReplyToId1 = table.Column<int>(nullable: true),
InReplyToId = table.Column<Guid>(nullable: true),
Status = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GanjoorComments", x => x.Id);
table.ForeignKey(
name: "FK_GanjoorComments_GanjoorComments_InReplyToId1",
column: x => x.InReplyToId1,
principalTable: "GanjoorComments",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_GanjoorComments_GanjoorPoems_PoemId",
column: x => x.PoemId,
principalTable: "GanjoorPoems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GanjoorComments_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_GanjoorComments_InReplyToId1",
table: "GanjoorComments",
column: "InReplyToId1");
migrationBuilder.CreateIndex(
name: "IX_GanjoorComments_PoemId",
table: "GanjoorComments",
column: "PoemId");
migrationBuilder.CreateIndex(
name: "IX_GanjoorComments_UserId",
table: "GanjoorComments",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GanjoorComments");
}
}
}

View File

@ -367,6 +367,57 @@ namespace RMuseum.Migrations
b.ToTable("GanjoorCategories");
});
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorComment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("AuthorEmail")
.HasColumnType("nvarchar(max)");
b.Property<string>("AuthorIpAddress")
.HasColumnType("nvarchar(max)");
b.Property<string>("AuthorName")
.HasColumnType("nvarchar(max)");
b.Property<string>("AuthorUrl")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CommentDate")
.HasColumnType("datetime2");
b.Property<string>("HtmlComment")
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("InReplyToId")
.HasColumnType("uniqueidentifier");
b.Property<int?>("InReplyToId1")
.HasColumnType("int");
b.Property<int>("PoemId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<Guid?>("UserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("InReplyToId1");
b.HasIndex("PoemId");
b.HasIndex("UserId");
b.ToTable("GanjoorComments");
});
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorMetre", b =>
{
b.Property<int>("Id")
@ -1790,6 +1841,23 @@ namespace RMuseum.Migrations
.IsRequired();
});
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorComment", b =>
{
b.HasOne("RMuseum.Models.Ganjoor.GanjoorComment", "InReplyTo")
.WithMany()
.HasForeignKey("InReplyToId1");
b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoem", "Poem")
.WithMany()
.HasForeignKey("PoemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("RSecurityBackend.Models.Auth.Db.RAppUser", "User")
.WithMany()
.HasForeignKey("UserId");
});
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorPage", b =>
{
b.HasOne("RMuseum.Models.Ganjoor.GanjoorCat", "Cat")

View File

@ -42,8 +42,9 @@ namespace RMuseum.Services.Implementation
var job = (await jobProgressServiceEF.NewJob("GanjoorService:ImportFromMySql", "pre open connection")).Result;
var resComments = await _ImportCommentsDataFromMySql(context, jobProgressServiceEF, job);
if(resComments.Result)//temporary
if(!resComments.Result)
{
await jobProgressServiceEF.UpdateJob(job.Id, job.Progress, "", false, resComments.ExceptionString);
return;
}
@ -520,6 +521,10 @@ namespace RMuseum.Services.Implementation
Status = row["comment_approved"].ToString() == "1" ? PublishStatus.Published : PublishStatus.Awaiting
};
var poem = await context.GanjoorPoems.Where(p => p.Id == comment.PoemId).SingleOrDefaultAsync();
if (poem == null)
continue;
context.GanjoorComments.Add(comment);

View File

@ -17,7 +17,7 @@
},
"Security": {
"Secret": "k4Fy7pDsc0LgXQ8PCCfZtwmju5Ed8asc",
"DefaultTokenExpirationInSeconds": "60"
"DefaultTokenExpirationInSeconds": "3600"
},
"SmptConfig": {
"Server": "smtp.gmail.com",

View File

@ -1423,7 +1423,7 @@ namespace RSecurityBackend.Services.Implementation
{
RAppUser admin = new RAppUser()
{
UserName = "admin",
UserName = "admin@ganjoor.net",
FirstName = "راهبر",
SureName = "سیستم",
Email = "admin@ganjoor.net",