diff --git a/pgLabII/App.axaml.cs b/pgLabII/App.axaml.cs index 799f898..4403271 100644 --- a/pgLabII/App.axaml.cs +++ b/pgLabII/App.axaml.cs @@ -49,6 +49,6 @@ public partial class App : Application using var scope = services.CreateScope(); var db = services.GetRequiredService(); - //db.Database.Migrate(); + db.Database.Migrate(); } } diff --git a/pgLabII/EditHistoryManager/EditHistoryManager.cs b/pgLabII/EditHistoryManager/EditHistoryManager.cs index 439bfed..45ba53d 100644 --- a/pgLabII/EditHistoryManager/EditHistoryManager.cs +++ b/pgLabII/EditHistoryManager/EditHistoryManager.cs @@ -84,9 +84,9 @@ public class EditHistoryManager : IEditHistoryManager public void SaveToDatabase() { - // _db.EditHistory.AddRange(_pendingEdits); - // _db.SaveChanges(); - // _pendingEdits.Clear(); + _db.EditHistory.AddRange(_pendingEdits); + _db.SaveChanges(); + _pendingEdits.Clear(); } public IReadOnlyList GetHistory() => _pendingEdits.AsReadOnly(); diff --git a/pgLabII/Infra/LocalDb.cs b/pgLabII/Infra/LocalDb.cs index dacee75..2d1343b 100644 --- a/pgLabII/Infra/LocalDb.cs +++ b/pgLabII/Infra/LocalDb.cs @@ -1,4 +1,5 @@ using System; +using Avalonia.Controls.Shapes; using Avalonia.Media; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -16,8 +17,9 @@ public class LocalDb : DbContext public LocalDb() { - var folder = Environment.SpecialFolder.LocalApplicationData; - var path = Environment.GetFolderPath(folder); + var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + path = System.IO.Path.Join(path, "pgLabII"); + System.IO.Directory.CreateDirectory(path); DbPath = System.IO.Path.Join(path, "local.db"); } diff --git a/pgLabII/Migrations/20251025162617_First.Designer.cs b/pgLabII/Migrations/20251025162617_First.Designer.cs new file mode 100644 index 0000000..6020602 --- /dev/null +++ b/pgLabII/Migrations/20251025162617_First.Designer.cs @@ -0,0 +1,139 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using pgLabII.Infra; + +#nullable disable + +namespace pgLabII.Migrations +{ + [DbContext(typeof(LocalDb))] + [Migration("20251025162617_First")] + partial class First + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.8"); + + modelBuilder.Entity("pgLabII.Model.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BaseCopyFilename") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("LastModified") + .HasColumnType("TEXT"); + + b.Property("OriginalFilename") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DocumentId") + .HasColumnType("INTEGER"); + + b.Property("InsertedText") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Offset") + .HasColumnType("INTEGER"); + + b.Property("RemovedText") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId", "Timestamp"); + + b.ToTable("EditHistory"); + }); + + modelBuilder.Entity("pgLabII.Model.ServerConfigurationEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ColorArgb") + .HasColumnType("INTEGER"); + + b.Property("ColorEnabled") + .HasColumnType("INTEGER"); + + b.Property("Host") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("InitialDatabase") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Port") + .HasColumnType("INTEGER"); + + b.Property("SslMode") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("ServerConfigurations"); + }); + + modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b => + { + b.HasOne("pgLabII.Model.Document", "Document") + .WithMany("EditHistory") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("pgLabII.Model.Document", b => + { + b.Navigation("EditHistory"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/pgLabII/Migrations/20251025162617_First.cs b/pgLabII/Migrations/20251025162617_First.cs new file mode 100644 index 0000000..8b042a4 --- /dev/null +++ b/pgLabII/Migrations/20251025162617_First.cs @@ -0,0 +1,92 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace pgLabII.Migrations +{ + /// + public partial class First : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Documents", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + OriginalFilename = table.Column(type: "TEXT", nullable: false), + BaseCopyFilename = table.Column(type: "TEXT", nullable: false), + Created = table.Column(type: "TEXT", nullable: false), + LastModified = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Documents", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ServerConfigurations", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Host = table.Column(type: "TEXT", nullable: false), + Port = table.Column(type: "INTEGER", nullable: false), + InitialDatabase = table.Column(type: "TEXT", nullable: false), + SslMode = table.Column(type: "INTEGER", nullable: false), + ColorEnabled = table.Column(type: "INTEGER", nullable: false), + ColorArgb = table.Column(type: "INTEGER", nullable: false), + UserName = table.Column(type: "TEXT", nullable: false), + Password = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ServerConfigurations", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EditHistory", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + DocumentId = table.Column(type: "INTEGER", nullable: false), + Timestamp = table.Column(type: "TEXT", nullable: false), + Offset = table.Column(type: "INTEGER", nullable: false), + InsertedText = table.Column(type: "TEXT", nullable: false), + RemovedText = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EditHistory", x => x.Id); + table.ForeignKey( + name: "FK_EditHistory_Documents_DocumentId", + column: x => x.DocumentId, + principalTable: "Documents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_EditHistory_DocumentId_Timestamp", + table: "EditHistory", + columns: new[] { "DocumentId", "Timestamp" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "EditHistory"); + + migrationBuilder.DropTable( + name: "ServerConfigurations"); + + migrationBuilder.DropTable( + name: "Documents"); + } + } +} diff --git a/pgLabII/Migrations/LocalDbModelSnapshot.cs b/pgLabII/Migrations/LocalDbModelSnapshot.cs new file mode 100644 index 0000000..c860147 --- /dev/null +++ b/pgLabII/Migrations/LocalDbModelSnapshot.cs @@ -0,0 +1,136 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using pgLabII.Infra; + +#nullable disable + +namespace pgLabII.Migrations +{ + [DbContext(typeof(LocalDb))] + partial class LocalDbModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.8"); + + modelBuilder.Entity("pgLabII.Model.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BaseCopyFilename") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Created") + .HasColumnType("TEXT"); + + b.Property("LastModified") + .HasColumnType("TEXT"); + + b.Property("OriginalFilename") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DocumentId") + .HasColumnType("INTEGER"); + + b.Property("InsertedText") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Offset") + .HasColumnType("INTEGER"); + + b.Property("RemovedText") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Timestamp") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId", "Timestamp"); + + b.ToTable("EditHistory"); + }); + + modelBuilder.Entity("pgLabII.Model.ServerConfigurationEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ColorArgb") + .HasColumnType("INTEGER"); + + b.Property("ColorEnabled") + .HasColumnType("INTEGER"); + + b.Property("Host") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("InitialDatabase") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Port") + .HasColumnType("INTEGER"); + + b.Property("SslMode") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("ServerConfigurations"); + }); + + modelBuilder.Entity("pgLabII.Model.EditHistoryEntry", b => + { + b.HasOne("pgLabII.Model.Document", "Document") + .WithMany("EditHistory") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("pgLabII.Model.Document", b => + { + b.Navigation("EditHistory"); + }); +#pragma warning restore 612, 618 + } + } +}