Added persistent unique ids to all elements
This commit is contained in:
parent
abb533f75b
commit
c2c8a36ad2
@ -6,6 +6,8 @@ public sealed class Section
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public Guid UniqueId { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
|
@ -7,6 +7,8 @@ public sealed class Setting
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public Guid UniqueId { get; set; }
|
||||
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
public string TextValue { get; set; } = string.Empty;
|
||||
|
@ -6,6 +6,8 @@ public sealed class TextElement
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public Guid UniqueId { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
public sealed class Translation
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public Guid UniqueId { get; set; }
|
||||
|
||||
public TextElement TextElement { get; set; }
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
using DataModel.Database.Common;
|
||||
|
||||
namespace DataModel.MigrationScripts;
|
||||
|
||||
public static class Script202211AddUniqueIds
|
||||
{
|
||||
public static async Task PostMigrationAsync(DataContext db)
|
||||
{
|
||||
await foreach (var setting in db.Settings)
|
||||
setting.UniqueId = Guid.NewGuid();
|
||||
|
||||
await foreach(var section in db.Sections)
|
||||
section.UniqueId = Guid.NewGuid();
|
||||
|
||||
await foreach (var textElement in db.TextElements)
|
||||
textElement.UniqueId = Guid.NewGuid();
|
||||
|
||||
await foreach (var translation in db.Translations)
|
||||
translation.UniqueId = Guid.NewGuid();
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
223
I18N Commander/DataModel/Migrations/20221106193544_202211AddUniqueIds.Designer.cs
generated
Normal file
223
I18N Commander/DataModel/Migrations/20221106193544_202211AddUniqueIds.Designer.cs
generated
Normal file
@ -0,0 +1,223 @@
|
||||
// <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("20221106193544_202211AddUniqueIds")]
|
||||
partial class _202211AddUniqueIds
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.9");
|
||||
|
||||
modelBuilder.Entity("DataModel.Database.Section", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DataKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Depth")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DataKey");
|
||||
|
||||
b.HasIndex("Depth");
|
||||
|
||||
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<string>("Code")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("GuidValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("IntegerValue")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("TextValue")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BoolValue");
|
||||
|
||||
b.HasIndex("Code")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("GuidValue");
|
||||
|
||||
b.HasIndex("Id");
|
||||
|
||||
b.HasIndex("IntegerValue");
|
||||
|
||||
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<bool>("IsMultiLine")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("SectionId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Code");
|
||||
|
||||
b.HasIndex("Id");
|
||||
|
||||
b.HasIndex("IsMultiLine");
|
||||
|
||||
b.HasIndex("Name");
|
||||
|
||||
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.Property<bool>("TranslateManual")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Culture");
|
||||
|
||||
b.HasIndex("Id");
|
||||
|
||||
b.HasIndex("Text");
|
||||
|
||||
b.HasIndex("TextElementId");
|
||||
|
||||
b.HasIndex("TranslateManual");
|
||||
|
||||
b.ToTable("Translations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataModel.Database.Section", b =>
|
||||
{
|
||||
b.HasOne("DataModel.Database.Section", "Parent")
|
||||
.WithMany()
|
||||
.HasForeignKey("ParentId");
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DataModel.Migrations
|
||||
{
|
||||
public partial class _202211AddUniqueIds : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "UniqueId",
|
||||
table: "Translations",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "UniqueId",
|
||||
table: "TextElements",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "UniqueId",
|
||||
table: "Settings",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "UniqueId",
|
||||
table: "Sections",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "UniqueId",
|
||||
table: "Translations");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "UniqueId",
|
||||
table: "TextElements");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "UniqueId",
|
||||
table: "Settings");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "UniqueId",
|
||||
table: "Sections");
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,9 @@ namespace DataModel.Migrations
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DataKey");
|
||||
@ -75,6 +78,9 @@ namespace DataModel.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BoolValue");
|
||||
@ -113,6 +119,9 @@ namespace DataModel.Migrations
|
||||
b.Property<int>("SectionId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Code");
|
||||
@ -148,6 +157,9 @@ namespace DataModel.Migrations
|
||||
b.Property<bool>("TranslateManual")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("UniqueId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Culture");
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DataModel.Database.Common;
|
||||
using DataModel.MigrationScripts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -27,6 +28,12 @@ public static class Setup
|
||||
}
|
||||
|
||||
await dbContext.Database.MigrateAsync();
|
||||
|
||||
//
|
||||
// Post migration actions:
|
||||
//
|
||||
if (pendingMigrations.Contains("20221106193544_202211AddUniqueIds"))
|
||||
await Script202211AddUniqueIds.PostMigrationAsync(dbContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2,5 +2,5 @@
|
||||
|
||||
public static class Version
|
||||
{
|
||||
public static string Text => $"v0.7.0 (2022-11-06), .NET {Environment.Version}";
|
||||
public static string Text => $"v0.7.1 (2022-11-06), .NET {Environment.Version}";
|
||||
}
|
Loading…
Reference in New Issue
Block a user