diff --git a/.gitignore b/.gitignore
index ca1c7a3..33e5e1e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,6 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+# sqlite databases
+*.db
+*.sqlite
\ No newline at end of file
diff --git a/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.Designer.cs b/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.Designer.cs
new file mode 100644
index 0000000..fb4382f
--- /dev/null
+++ b/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.Designer.cs
@@ -0,0 +1,152 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using PiwigoDirectorySync.Persistence;
+
+#nullable disable
+
+namespace PiwigoDirectorySync.Migrations
+{
+ [DbContext(typeof(PersistenceContext))]
+ [Migration("20230830195902_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.10");
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.AlbumEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("DirectoryName")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("ParentId")
+ .HasColumnType("INTEGER");
+
+ b.Property("PiwigoAlbumId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ServerId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ParentId");
+
+ b.HasIndex("PiwigoAlbumId");
+
+ b.HasIndex("ServerId");
+
+ b.ToTable("PiwigoAlbums");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.ImageEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AlbumId")
+ .HasColumnType("INTEGER");
+
+ b.Property("DeleteRequired")
+ .HasColumnType("INTEGER");
+
+ b.Property("FilePath")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("LastChange")
+ .HasColumnType("TEXT");
+
+ b.Property("Md5Sum")
+ .HasColumnType("TEXT");
+
+ b.Property("ServerImageId")
+ .HasColumnType("INTEGER");
+
+ b.Property("UploadRequired")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AlbumId");
+
+ b.ToTable("PiwigoImages");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.PiwigoServerEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("RootDirectory")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Url")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Username")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Name")
+ .IsUnique();
+
+ b.ToTable("PiwigoServers");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.AlbumEntity", b =>
+ {
+ b.HasOne("PiwigoDirectorySync.Persistence.AlbumEntity", "Parent")
+ .WithMany()
+ .HasForeignKey("ParentId");
+
+ b.HasOne("PiwigoDirectorySync.Persistence.PiwigoServerEntity", "Server")
+ .WithMany()
+ .HasForeignKey("ServerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Parent");
+
+ b.Navigation("Server");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.ImageEntity", b =>
+ {
+ b.HasOne("PiwigoDirectorySync.Persistence.AlbumEntity", "Album")
+ .WithMany()
+ .HasForeignKey("AlbumId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Album");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.cs b/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.cs
new file mode 100644
index 0000000..c1c4fba
--- /dev/null
+++ b/PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.cs
@@ -0,0 +1,123 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace PiwigoDirectorySync.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "PiwigoServers",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ Name = table.Column(type: "TEXT", nullable: false),
+ Url = table.Column(type: "TEXT", nullable: false),
+ Username = table.Column(type: "TEXT", nullable: false),
+ Password = table.Column(type: "TEXT", nullable: false),
+ RootDirectory = table.Column(type: "TEXT", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_PiwigoServers", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "PiwigoAlbums",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ PiwigoAlbumId = table.Column(type: "INTEGER", nullable: true),
+ DirectoryName = table.Column(type: "TEXT", nullable: false),
+ ParentId = table.Column(type: "INTEGER", nullable: true),
+ ServerId = table.Column(type: "INTEGER", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_PiwigoAlbums", x => x.Id);
+ table.ForeignKey(
+ name: "FK_PiwigoAlbums_PiwigoAlbums_ParentId",
+ column: x => x.ParentId,
+ principalTable: "PiwigoAlbums",
+ principalColumn: "Id");
+ table.ForeignKey(
+ name: "FK_PiwigoAlbums_PiwigoServers_ServerId",
+ column: x => x.ServerId,
+ principalTable: "PiwigoServers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "PiwigoImages",
+ columns: table => new
+ {
+ Id = table.Column(type: "INTEGER", nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ ServerImageId = table.Column(type: "INTEGER", nullable: true),
+ FilePath = table.Column(type: "TEXT", nullable: false),
+ LastChange = table.Column(type: "TEXT", nullable: false),
+ Md5Sum = table.Column(type: "TEXT", nullable: true),
+ AlbumId = table.Column(type: "INTEGER", nullable: false),
+ UploadRequired = table.Column(type: "INTEGER", nullable: false),
+ DeleteRequired = table.Column(type: "INTEGER", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_PiwigoImages", x => x.Id);
+ table.ForeignKey(
+ name: "FK_PiwigoImages_PiwigoAlbums_AlbumId",
+ column: x => x.AlbumId,
+ principalTable: "PiwigoAlbums",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_PiwigoAlbums_ParentId",
+ table: "PiwigoAlbums",
+ column: "ParentId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_PiwigoAlbums_PiwigoAlbumId",
+ table: "PiwigoAlbums",
+ column: "PiwigoAlbumId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_PiwigoAlbums_ServerId",
+ table: "PiwigoAlbums",
+ column: "ServerId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_PiwigoImages_AlbumId",
+ table: "PiwigoImages",
+ column: "AlbumId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_PiwigoServers_Name",
+ table: "PiwigoServers",
+ column: "Name",
+ unique: true);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "PiwigoImages");
+
+ migrationBuilder.DropTable(
+ name: "PiwigoAlbums");
+
+ migrationBuilder.DropTable(
+ name: "PiwigoServers");
+ }
+ }
+}
diff --git a/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs b/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs
new file mode 100644
index 0000000..0ae48b7
--- /dev/null
+++ b/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs
@@ -0,0 +1,149 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using PiwigoDirectorySync.Persistence;
+
+#nullable disable
+
+namespace PiwigoDirectorySync.Migrations
+{
+ [DbContext(typeof(PersistenceContext))]
+ partial class PersistenceContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.10");
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.AlbumEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("DirectoryName")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("ParentId")
+ .HasColumnType("INTEGER");
+
+ b.Property("PiwigoAlbumId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ServerId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ParentId");
+
+ b.HasIndex("PiwigoAlbumId");
+
+ b.HasIndex("ServerId");
+
+ b.ToTable("PiwigoAlbums");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.ImageEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AlbumId")
+ .HasColumnType("INTEGER");
+
+ b.Property("DeleteRequired")
+ .HasColumnType("INTEGER");
+
+ b.Property("FilePath")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("LastChange")
+ .HasColumnType("TEXT");
+
+ b.Property("Md5Sum")
+ .HasColumnType("TEXT");
+
+ b.Property("ServerImageId")
+ .HasColumnType("INTEGER");
+
+ b.Property("UploadRequired")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AlbumId");
+
+ b.ToTable("PiwigoImages");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.PiwigoServerEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("RootDirectory")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Url")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property("Username")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Name")
+ .IsUnique();
+
+ b.ToTable("PiwigoServers");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.AlbumEntity", b =>
+ {
+ b.HasOne("PiwigoDirectorySync.Persistence.AlbumEntity", "Parent")
+ .WithMany()
+ .HasForeignKey("ParentId");
+
+ b.HasOne("PiwigoDirectorySync.Persistence.PiwigoServerEntity", "Server")
+ .WithMany()
+ .HasForeignKey("ServerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Parent");
+
+ b.Navigation("Server");
+ });
+
+ modelBuilder.Entity("PiwigoDirectorySync.Persistence.ImageEntity", b =>
+ {
+ b.HasOne("PiwigoDirectorySync.Persistence.AlbumEntity", "Album")
+ .WithMany()
+ .HasForeignKey("AlbumId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Album");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/PiwigoDirectorySync/Persistence/AlbumEntity.cs b/PiwigoDirectorySync/Persistence/AlbumEntity.cs
index 28ceb69..ea62072 100644
--- a/PiwigoDirectorySync/Persistence/AlbumEntity.cs
+++ b/PiwigoDirectorySync/Persistence/AlbumEntity.cs
@@ -4,19 +4,23 @@ using Microsoft.EntityFrameworkCore;
namespace PiwigoDirectorySync.Persistence;
+[Index(nameof(ParentId))]
+[Index(nameof(PiwigoAlbumId))]
public class AlbumEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
+ public int? PiwigoAlbumId { get; set; }
+ public required string DirectoryName { get; set; }
+
public int? ParentId { get; set; }
public AlbumEntity? Parent { get; set; }
+
public required int ServerId { get; set; }
public PiwigoServerEntity Server { get; set; } = null!;
- public required string Name { get; set; }
- public required string DirectoryName { get; set; }
- public string FullDirectory => Parent is not null ? $"{Parent.FullDirectory}{Path.DirectorySeparatorChar}{DirectoryName}" : DirectoryName;
- public int? PiwigoAlbumId { get; set; }
+ public string FullPath =>
+ Parent is not null ? $"{Parent.FullPath}{Path.DirectorySeparatorChar}{DirectoryName}" : $"{Server.RootDirectory}{Path.DirectorySeparatorChar}{DirectoryName}";
}
\ No newline at end of file
diff --git a/PiwigoDirectorySync/Persistence/ImageEntity.cs b/PiwigoDirectorySync/Persistence/ImageEntity.cs
index 201ae8b..d319c41 100644
--- a/PiwigoDirectorySync/Persistence/ImageEntity.cs
+++ b/PiwigoDirectorySync/Persistence/ImageEntity.cs
@@ -4,17 +4,22 @@ using Microsoft.EntityFrameworkCore;
namespace PiwigoDirectorySync.Persistence;
+[Index(nameof(AlbumId))]
public class ImageEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
- public required string Filename { get; set; }
+ public int? ServerImageId { get; set; }
+
+ public required string FilePath { get; set; }
+
public DateTime LastChange { get; set; }
public string? Md5Sum { get; set; }
+
public required int AlbumId { get; set; }
public AlbumEntity Album { get; set; } = null!;
- public int ServerImageId { get; set; }
+
public bool UploadRequired { get; set; }
public bool DeleteRequired { get; set; }
}
\ No newline at end of file
diff --git a/PiwigoDirectorySync/Persistence/PiwigoServerEntity.cs b/PiwigoDirectorySync/Persistence/PiwigoServerEntity.cs
index c51668e..063077e 100644
--- a/PiwigoDirectorySync/Persistence/PiwigoServerEntity.cs
+++ b/PiwigoDirectorySync/Persistence/PiwigoServerEntity.cs
@@ -10,7 +10,6 @@ public class PiwigoServerEntity
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
-
public required string Name { get; set; }
public required string Url { get; set; }
public required string Username { get; set; }
diff --git a/PiwigoDirectorySync/addMigration.ps1 b/PiwigoDirectorySync/dbAddMigration.ps1
similarity index 50%
rename from PiwigoDirectorySync/addMigration.ps1
rename to PiwigoDirectorySync/dbAddMigration.ps1
index 5fd66a3..23ea7bc 100644
--- a/PiwigoDirectorySync/addMigration.ps1
+++ b/PiwigoDirectorySync/dbAddMigration.ps1
@@ -2,4 +2,3 @@ $comment=$args[0]
write-host "adding migration for Sqlite"
dotnet ef migrations add --project PiwigoDirectorySync.csproj --startup-project PiwigoDirectorySync.csproj --context PiwigoDirectorySync.Persistence.PersistenceContext "$comment" --output-dir Migrations -- --DbProvider Sqlite
-#dotnet ef migrations add --project PiwigoDirectorySync/PiwigoDirectorySync.csproj --startup-project PiwigoDirectorySync/PiwigoDirectorySync.csproj --context PiwigoDirectorySync.Persistence.Persistence.PersistenceContext "$comment" --output-dir Migrations -- --DbProvider Sqlite
diff --git a/PiwigoDirectorySync/dbUpdateSqlite.ps1 b/PiwigoDirectorySync/dbUpdateSqlite.ps1
new file mode 100644
index 0000000..08914b0
--- /dev/null
+++ b/PiwigoDirectorySync/dbUpdateSqlite.ps1
@@ -0,0 +1,2 @@
+write-host "updating Sqlite db"
+dotnet ef database update --project PiwigoDirectorySync.csproj --startup-project PiwigoDirectorySync.csproj --context PiwigoDirectorySync.Persistence.PersistenceContext --configuration Debug -- DbProvider Sqlite
diff --git a/identifier.sqlite b/identifier.sqlite
new file mode 100644
index 0000000..e69de29