adds initial db context and db setup
This commit is contained in:
parent
28f4ec09f2
commit
2e130e8aad
3
.gitignore
vendored
3
.gitignore
vendored
@ -398,3 +398,6 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
# sqlite databases
|
||||
*.db
|
||||
*.sqlite
|
152
PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.Designer.cs
generated
Normal file
152
PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,152 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DirectoryName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("PiwigoAlbumId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AlbumId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("DeleteRequired")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("FilePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastChange")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Md5Sum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("UploadRequired")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AlbumId");
|
||||
|
||||
b.ToTable("PiwigoImages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PiwigoDirectorySync.Persistence.PiwigoServerEntity", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RootDirectory")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("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
|
||||
}
|
||||
}
|
||||
}
|
123
PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.cs
Normal file
123
PiwigoDirectorySync/Migrations/20230830195902_InitialCreate.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PiwigoDirectorySync.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PiwigoServers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Url = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Username = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Password = table.Column<string>(type: "TEXT", nullable: false),
|
||||
RootDirectory = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PiwigoServers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PiwigoAlbums",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
PiwigoAlbumId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
DirectoryName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
ParentId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ServerId = table.Column<int>(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<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
ServerImageId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
FilePath = table.Column<string>(type: "TEXT", nullable: false),
|
||||
LastChange = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Md5Sum = table.Column<string>(type: "TEXT", nullable: true),
|
||||
AlbumId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
UploadRequired = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
DeleteRequired = table.Column<bool>(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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "PiwigoImages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PiwigoAlbums");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PiwigoServers");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
// <auto-generated />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DirectoryName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("PiwigoAlbumId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("AlbumId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("DeleteRequired")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("FilePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastChange")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Md5Sum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("UploadRequired")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AlbumId");
|
||||
|
||||
b.ToTable("PiwigoImages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PiwigoDirectorySync.Persistence.PiwigoServerEntity", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RootDirectory")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("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
|
||||
}
|
||||
}
|
||||
}
|
@ -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}";
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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; }
|
||||
|
@ -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
|
2
PiwigoDirectorySync/dbUpdateSqlite.ps1
Normal file
2
PiwigoDirectorySync/dbUpdateSqlite.ps1
Normal file
@ -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
|
0
identifier.sqlite
Normal file
0
identifier.sqlite
Normal file
Loading…
Reference in New Issue
Block a user