diff --git a/I18N Commander/DataModel/Database/Common/DataContext.cs b/I18N Commander/DataModel/Database/Common/DataContext.cs index 43d1c5d..3d9971d 100644 --- a/I18N Commander/DataModel/Database/Common/DataContext.cs +++ b/I18N Commander/DataModel/Database/Common/DataContext.cs @@ -6,6 +6,12 @@ public sealed class DataContext : DbContext { public DbSet? Settings { get; set; } + public DbSet
? Sections { get; set; } + + public DbSet? TextElements { get; set; } + + public DbSet? Translations { get; set; } + public DataContext(DbContextOptions contextOptions) : base(contextOptions) { } @@ -14,7 +20,7 @@ public sealed class DataContext : DbContext { base.OnModelCreating(modelBuilder); - #region Ideas + #region Settings modelBuilder.Entity().HasIndex(n => n.Id); modelBuilder.Entity().HasIndex(n => n.Name).IsUnique(); @@ -24,5 +30,27 @@ public sealed class DataContext : DbContext modelBuilder.Entity().HasIndex(n => n.TextValue); #endregion + + #region Sections + + modelBuilder.Entity
().HasIndex(n => n.Id); + modelBuilder.Entity
().HasIndex(n => n.Name); + + #endregion + + #region TextElements + + modelBuilder.Entity().HasIndex(n => n.Id); + modelBuilder.Entity().HasIndex(n => n.Code); + + #endregion + + #region Translations + + modelBuilder.Entity().HasIndex(n => n.Id); + modelBuilder.Entity().HasIndex(n => n.Culture); + modelBuilder.Entity().HasIndex(n => n.Text); + + #endregion } } \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/Section.cs b/I18N Commander/DataModel/Database/Section.cs new file mode 100644 index 0000000..b7f4c60 --- /dev/null +++ b/I18N Commander/DataModel/Database/Section.cs @@ -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 TextElements { get; set; } +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/Setting.cs b/I18N Commander/DataModel/Database/Setting.cs index 3f847d6..cf0dc62 100644 --- a/I18N Commander/DataModel/Database/Setting.cs +++ b/I18N Commander/DataModel/Database/Setting.cs @@ -2,7 +2,7 @@ namespace DataModel.Database; -public class Setting +public sealed class Setting { [Key] public int Id { get; set; } diff --git a/I18N Commander/DataModel/Database/TextElement.cs b/I18N Commander/DataModel/Database/TextElement.cs new file mode 100644 index 0000000..2135ffe --- /dev/null +++ b/I18N Commander/DataModel/Database/TextElement.cs @@ -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 Translations { get; set; } +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/Translation.cs b/I18N Commander/DataModel/Database/Translation.cs new file mode 100644 index 0000000..2b5b874 --- /dev/null +++ b/I18N Commander/DataModel/Database/Translation.cs @@ -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; +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.Designer.cs b/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.Designer.cs new file mode 100644 index 0000000..8a363f7 --- /dev/null +++ b/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.Designer.cs @@ -0,0 +1,186 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BoolValue") + .HasColumnType("INTEGER"); + + b.Property("GuidValue") + .HasColumnType("TEXT"); + + b.Property("IntegerValue") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Code") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Culture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Text") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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 + } + } +} diff --git a/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.cs b/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.cs new file mode 100644 index 0000000..e9a2cad --- /dev/null +++ b/I18N Commander/DataModel/Migrations/20220612194509_202206AddMainEntities.cs @@ -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(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + ParentId = table.Column(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(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Code = table.Column(type: "TEXT", nullable: false), + SectionId = table.Column(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(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TextElementId = table.Column(type: "INTEGER", nullable: false), + Culture = table.Column(type: "TEXT", nullable: false), + Text = table.Column(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"); + } + } +} diff --git a/I18N Commander/DataModel/Migrations/DataContextModelSnapshot.cs b/I18N Commander/DataModel/Migrations/DataContextModelSnapshot.cs index 4bfc41b..fd8d8b5 100644 --- a/I18N Commander/DataModel/Migrations/DataContextModelSnapshot.cs +++ b/I18N Commander/DataModel/Migrations/DataContextModelSnapshot.cs @@ -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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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("Id") @@ -57,6 +81,103 @@ namespace DataModel.Migrations b.ToTable("Settings"); }); + + modelBuilder.Entity("DataModel.Database.TextElement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Code") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Culture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Text") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("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 } } diff --git a/I18N Commander/DataModel/cmdAddMigration.cmd b/I18N Commander/DataModel/cmdAddMigration.cmd index 7d9244e..cb50502 100644 --- a/I18N Commander/DataModel/cmdAddMigration.cmd +++ b/I18N Commander/DataModel/cmdAddMigration.cmd @@ -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% diff --git a/I18N Commander/DataModel/cmdUndoMigration.cmd b/I18N Commander/DataModel/cmdUndoMigration.cmd index 992113f..9794763 100644 --- a/I18N Commander/DataModel/cmdUndoMigration.cmd +++ b/I18N Commander/DataModel/cmdUndoMigration.cmd @@ -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% diff --git a/project for migrations.i18nc b/project for migrations.i18nc index e69de29..fce11e3 100644 Binary files a/project for migrations.i18nc and b/project for migrations.i18nc differ