Merge branch '4-add-main-entities-aka-data-model' into 'main'

Resolve "Add main entities aka data model"

Closes #4

See merge request open-source/dotnet/i18n-commander!4
This commit is contained in:
Thorsten 2022-06-12 19:47:14 +00:00
commit ba5c429f93
11 changed files with 516 additions and 4 deletions

View File

@ -6,6 +6,12 @@ public sealed class DataContext : DbContext
{
public DbSet<Setting>? Settings { get; set; }
public DbSet<Section>? Sections { get; set; }
public DbSet<TextElement>? TextElements { get; set; }
public DbSet<Translation>? Translations { get; set; }
public DataContext(DbContextOptions<DataContext> contextOptions) : base(contextOptions)
{
}
@ -14,7 +20,7 @@ public sealed class DataContext : DbContext
{
base.OnModelCreating(modelBuilder);
#region Ideas
#region Settings
modelBuilder.Entity<Setting>().HasIndex(n => n.Id);
modelBuilder.Entity<Setting>().HasIndex(n => n.Name).IsUnique();
@ -24,5 +30,27 @@ public sealed class DataContext : DbContext
modelBuilder.Entity<Setting>().HasIndex(n => n.TextValue);
#endregion
#region Sections
modelBuilder.Entity<Section>().HasIndex(n => n.Id);
modelBuilder.Entity<Section>().HasIndex(n => n.Name);
#endregion
#region TextElements
modelBuilder.Entity<TextElement>().HasIndex(n => n.Id);
modelBuilder.Entity<TextElement>().HasIndex(n => n.Code);
#endregion
#region Translations
modelBuilder.Entity<Translation>().HasIndex(n => n.Id);
modelBuilder.Entity<Translation>().HasIndex(n => n.Culture);
modelBuilder.Entity<Translation>().HasIndex(n => n.Text);
#endregion
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace DataModel.Database;
public sealed class Section
{
[Key]
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public Section Parent { get; set; }
public List<TextElement> TextElements { get; set; }
}

View File

@ -2,7 +2,7 @@
namespace DataModel.Database;
public class Setting
public sealed class Setting
{
[Key]
public int Id { get; set; }

View File

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace DataModel.Database;
public sealed class TextElement
{
[Key]
public int Id { get; set; }
public string Code { get; set; } = string.Empty;
public Section Section { get; set; }
public List<Translation> Translations { get; set; }
}

View File

@ -0,0 +1,12 @@
namespace DataModel.Database;
public sealed class Translation
{
public int Id { get; set; }
public TextElement TextElement { get; set; }
public string Culture { get; set; } = "en-US";
public string Text { get; set; } = string.Empty;
}

View File

@ -0,0 +1,186 @@
// <auto-generated />
using System;
using DataModel.Database.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DataModel.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20220612194509_202206AddMainEntities")]
partial class _202206AddMainEntities
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.5");
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("ParentId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Id");
b.HasIndex("Name");
b.HasIndex("ParentId");
b.ToTable("Sections");
});
modelBuilder.Entity("DataModel.Database.Setting", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("BoolValue")
.HasColumnType("INTEGER");
b.Property<Guid>("GuidValue")
.HasColumnType("TEXT");
b.Property<int>("IntegerValue")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TextValue")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("BoolValue");
b.HasIndex("GuidValue");
b.HasIndex("Id");
b.HasIndex("IntegerValue");
b.HasIndex("Name")
.IsUnique();
b.HasIndex("TextValue");
b.ToTable("Settings");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SectionId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Code");
b.HasIndex("Id");
b.HasIndex("SectionId");
b.ToTable("TextElements");
});
modelBuilder.Entity("DataModel.Database.Translation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Culture")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("TextElementId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Culture");
b.HasIndex("Id");
b.HasIndex("Text");
b.HasIndex("TextElementId");
b.ToTable("Translations");
});
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.HasOne("DataModel.Database.Section", "Parent")
.WithMany()
.HasForeignKey("ParentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Parent");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.HasOne("DataModel.Database.Section", "Section")
.WithMany("TextElements")
.HasForeignKey("SectionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Section");
});
modelBuilder.Entity("DataModel.Database.Translation", b =>
{
b.HasOne("DataModel.Database.TextElement", "TextElement")
.WithMany("Translations")
.HasForeignKey("TextElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("TextElement");
});
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.Navigation("TextElements");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.Navigation("Translations");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,135 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DataModel.Migrations
{
public partial class _202206AddMainEntities : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Sections",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
ParentId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sections", x => x.Id);
table.ForeignKey(
name: "FK_Sections_Sections_ParentId",
column: x => x.ParentId,
principalTable: "Sections",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TextElements",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Code = table.Column<string>(type: "TEXT", nullable: false),
SectionId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TextElements", x => x.Id);
table.ForeignKey(
name: "FK_TextElements_Sections_SectionId",
column: x => x.SectionId,
principalTable: "Sections",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Translations",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
TextElementId = table.Column<int>(type: "INTEGER", nullable: false),
Culture = table.Column<string>(type: "TEXT", nullable: false),
Text = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Translations", x => x.Id);
table.ForeignKey(
name: "FK_Translations_TextElements_TextElementId",
column: x => x.TextElementId,
principalTable: "TextElements",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Sections_Id",
table: "Sections",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_Sections_Name",
table: "Sections",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_Sections_ParentId",
table: "Sections",
column: "ParentId");
migrationBuilder.CreateIndex(
name: "IX_TextElements_Code",
table: "TextElements",
column: "Code");
migrationBuilder.CreateIndex(
name: "IX_TextElements_Id",
table: "TextElements",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_TextElements_SectionId",
table: "TextElements",
column: "SectionId");
migrationBuilder.CreateIndex(
name: "IX_Translations_Culture",
table: "Translations",
column: "Culture");
migrationBuilder.CreateIndex(
name: "IX_Translations_Id",
table: "Translations",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_Translations_Text",
table: "Translations",
column: "Text");
migrationBuilder.CreateIndex(
name: "IX_Translations_TextElementId",
table: "Translations",
column: "TextElementId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Translations");
migrationBuilder.DropTable(
name: "TextElements");
migrationBuilder.DropTable(
name: "Sections");
}
}
}

View File

@ -17,6 +17,30 @@ namespace DataModel.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.5");
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("ParentId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Id");
b.HasIndex("Name");
b.HasIndex("ParentId");
b.ToTable("Sections");
});
modelBuilder.Entity("DataModel.Database.Setting", b =>
{
b.Property<int>("Id")
@ -57,6 +81,103 @@ namespace DataModel.Migrations
b.ToTable("Settings");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("SectionId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Code");
b.HasIndex("Id");
b.HasIndex("SectionId");
b.ToTable("TextElements");
});
modelBuilder.Entity("DataModel.Database.Translation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Culture")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("TextElementId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("Culture");
b.HasIndex("Id");
b.HasIndex("Text");
b.HasIndex("TextElementId");
b.ToTable("Translations");
});
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.HasOne("DataModel.Database.Section", "Parent")
.WithMany()
.HasForeignKey("ParentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Parent");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.HasOne("DataModel.Database.Section", "Section")
.WithMany("TextElements")
.HasForeignKey("SectionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Section");
});
modelBuilder.Entity("DataModel.Database.Translation", b =>
{
b.HasOne("DataModel.Database.TextElement", "TextElement")
.WithMany("Translations")
.HasForeignKey("TextElementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("TextElement");
});
modelBuilder.Entity("DataModel.Database.Section", b =>
{
b.Navigation("TextElements");
});
modelBuilder.Entity("DataModel.Database.TextElement", b =>
{
b.Navigation("Translations");
});
#pragma warning restore 612, 618
}
}

View File

@ -1,4 +1,4 @@
@echo off
@echo off
set /p migrationName="Please enter the new migration's name: "
dotnet tool update --global dotnet-ef
dotnet ef migrations add %migrationName%

View File

@ -1,4 +1,4 @@
@echo off
@echo off
set /p migrationName="Please enter the migration's name which should be the **ACTIVE** one: "
dotnet tool update --global dotnet-ef
dotnet ef database update %migrationName%

Binary file not shown.