diff --git a/PiwigoDirectorySync/Migrations/20230911213151_AlbumPathIsUniqueWithinServer.Designer.cs b/PiwigoDirectorySync/Migrations/20230911213151_AlbumPathIsUniqueWithinServer.Designer.cs new file mode 100644 index 0000000..964d585 --- /dev/null +++ b/PiwigoDirectorySync/Migrations/20230911213151_AlbumPathIsUniqueWithinServer.Designer.cs @@ -0,0 +1,159 @@ +// +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("20230911213151_AlbumPathIsUniqueWithinServer")] + partial class AlbumPathIsUniqueWithinServer + { + /// + 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("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Path") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ServerAlbumId") + .HasColumnType("INTEGER"); + + b.Property("ServerId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("ServerAlbumId"); + + b.HasIndex("ServerId", "Path") + .IsUnique(); + + 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("ServerImageId"); + + b.HasIndex("AlbumId", "FilePath"); + + b.ToTable("PiwigoImages"); + }); + + modelBuilder.Entity("PiwigoDirectorySync.Persistence.ServerEntity", 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.ServerEntity", "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/20230911213151_AlbumPathIsUniqueWithinServer.cs b/PiwigoDirectorySync/Migrations/20230911213151_AlbumPathIsUniqueWithinServer.cs new file mode 100644 index 0000000..5e9d00c --- /dev/null +++ b/PiwigoDirectorySync/Migrations/20230911213151_AlbumPathIsUniqueWithinServer.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PiwigoDirectorySync.Migrations +{ + /// + public partial class AlbumPathIsUniqueWithinServer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_PiwigoAlbums_ServerId_Path", + table: "PiwigoAlbums"); + + migrationBuilder.CreateIndex( + name: "IX_PiwigoAlbums_ServerId_Path", + table: "PiwigoAlbums", + columns: new[] { "ServerId", "Path" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_PiwigoAlbums_ServerId_Path", + table: "PiwigoAlbums"); + + migrationBuilder.CreateIndex( + name: "IX_PiwigoAlbums_ServerId_Path", + table: "PiwigoAlbums", + columns: new[] { "ServerId", "Path" }); + } + } +} diff --git a/PiwigoDirectorySync/Migrations/20230911213415_ImagePathIsUniqueWithinAlbum.Designer.cs b/PiwigoDirectorySync/Migrations/20230911213415_ImagePathIsUniqueWithinAlbum.Designer.cs new file mode 100644 index 0000000..94781ef --- /dev/null +++ b/PiwigoDirectorySync/Migrations/20230911213415_ImagePathIsUniqueWithinAlbum.Designer.cs @@ -0,0 +1,160 @@ +// +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("20230911213415_ImagePathIsUniqueWithinAlbum")] + partial class ImagePathIsUniqueWithinAlbum + { + /// + 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("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Path") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ServerAlbumId") + .HasColumnType("INTEGER"); + + b.Property("ServerId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("ServerAlbumId"); + + b.HasIndex("ServerId", "Path") + .IsUnique(); + + 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("ServerImageId"); + + b.HasIndex("AlbumId", "FilePath") + .IsUnique(); + + b.ToTable("PiwigoImages"); + }); + + modelBuilder.Entity("PiwigoDirectorySync.Persistence.ServerEntity", 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.ServerEntity", "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/20230911213415_ImagePathIsUniqueWithinAlbum.cs b/PiwigoDirectorySync/Migrations/20230911213415_ImagePathIsUniqueWithinAlbum.cs new file mode 100644 index 0000000..e6ec667 --- /dev/null +++ b/PiwigoDirectorySync/Migrations/20230911213415_ImagePathIsUniqueWithinAlbum.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PiwigoDirectorySync.Migrations +{ + /// + public partial class ImagePathIsUniqueWithinAlbum : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_PiwigoImages_AlbumId_FilePath", + table: "PiwigoImages"); + + migrationBuilder.CreateIndex( + name: "IX_PiwigoImages_AlbumId_FilePath", + table: "PiwigoImages", + columns: new[] { "AlbumId", "FilePath" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_PiwigoImages_AlbumId_FilePath", + table: "PiwigoImages"); + + migrationBuilder.CreateIndex( + name: "IX_PiwigoImages_AlbumId_FilePath", + table: "PiwigoImages", + columns: new[] { "AlbumId", "FilePath" }); + } + } +} diff --git a/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs b/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs index bb27dde..ea38758 100644 --- a/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs +++ b/PiwigoDirectorySync/Migrations/PersistenceContextModelSnapshot.cs @@ -46,7 +46,8 @@ namespace PiwigoDirectorySync.Migrations b.HasIndex("ServerAlbumId"); - b.HasIndex("ServerId", "Path"); + b.HasIndex("ServerId", "Path") + .IsUnique(); b.ToTable("PiwigoAlbums"); }); @@ -83,7 +84,8 @@ namespace PiwigoDirectorySync.Migrations b.HasIndex("ServerImageId"); - b.HasIndex("AlbumId", "FilePath"); + b.HasIndex("AlbumId", "FilePath") + .IsUnique(); b.ToTable("PiwigoImages"); }); diff --git a/PiwigoDirectorySync/Persistence/AlbumEntity.cs b/PiwigoDirectorySync/Persistence/AlbumEntity.cs index 3c6fb2f..184e0d8 100644 --- a/PiwigoDirectorySync/Persistence/AlbumEntity.cs +++ b/PiwigoDirectorySync/Persistence/AlbumEntity.cs @@ -6,7 +6,7 @@ namespace PiwigoDirectorySync.Persistence; [Index(nameof(ParentId))] [Index(nameof(ServerAlbumId))] -[Index(nameof(ServerId), nameof(Path))] +[Index(nameof(ServerId), nameof(Path), IsUnique = true)] public class AlbumEntity { [Key] diff --git a/PiwigoDirectorySync/Persistence/BloggingContextFactory.cs b/PiwigoDirectorySync/Persistence/BloggingContextFactory.cs new file mode 100644 index 0000000..3e0b604 --- /dev/null +++ b/PiwigoDirectorySync/Persistence/BloggingContextFactory.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; + +namespace PiwigoDirectorySync.Persistence; + +public class BloggingContextFactory : IDesignTimeDbContextFactory +{ + public PersistenceContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseSqlite("Data Source=piwigoSync.db"); + return new PersistenceContext(optionsBuilder.Options); + } +} \ No newline at end of file diff --git a/PiwigoDirectorySync/Persistence/ImageEntity.cs b/PiwigoDirectorySync/Persistence/ImageEntity.cs index 399745a..d2812f0 100644 --- a/PiwigoDirectorySync/Persistence/ImageEntity.cs +++ b/PiwigoDirectorySync/Persistence/ImageEntity.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore; namespace PiwigoDirectorySync.Persistence; -[Index(nameof(AlbumId), nameof(FilePath))] +[Index(nameof(AlbumId), nameof(FilePath), IsUnique = true)] [Index(nameof(ServerImageId))] public class ImageEntity {