From e9226ef7c34f6c355e32ef4872a7d92f912be3f1 Mon Sep 17 00:00:00 2001 From: tschumpr Date: Tue, 28 May 2024 14:26:21 +0200 Subject: [PATCH] Add migration --- ...28121852_RenameDeliveryMandate.Designer.cs | 294 ++++++++++++++++++ .../20240528121852_RenameDeliveryMandate.cs | 103 ++++++ .../Migrations/ContextModelSnapshot.cs | 80 ++--- 3 files changed, 437 insertions(+), 40 deletions(-) create mode 100644 src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.Designer.cs create mode 100644 src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.cs diff --git a/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.Designer.cs b/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.Designer.cs new file mode 100644 index 00000000..632255b9 --- /dev/null +++ b/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.Designer.cs @@ -0,0 +1,294 @@ +// +using System; +using Geopilot.Api; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using NetTopologySuite.Geometries; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Geopilot.Api.Migrations +{ + [DbContext(typeof(Context))] + [Migration("20240528121852_RenameDeliveryMandate")] + partial class RenameDeliveryMandate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Geopilot.Api.Models.Asset", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AssetType") + .IsRequired() + .HasColumnType("varchar(24)"); + + b.Property("Deleted") + .HasColumnType("boolean"); + + b.Property("DeliveryId") + .HasColumnType("integer"); + + b.Property("FileHash") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("OriginalFilename") + .IsRequired() + .HasColumnType("text"); + + b.Property("SanitizedFilename") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("DeliveryId"); + + b.ToTable("Assets"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Delivery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DeclaringUserId") + .HasColumnType("integer"); + + b.Property("Deleted") + .HasColumnType("boolean"); + + b.Property("JobId") + .HasColumnType("uuid"); + + b.Property("MandateId") + .HasColumnType("integer"); + + b.Property("Partial") + .HasColumnType("boolean"); + + b.Property("PrecursorDeliveryId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DeclaringUserId"); + + b.HasIndex("MandateId"); + + b.HasIndex("PrecursorDeliveryId"); + + b.ToTable("Deliveries"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Mandate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FileTypes") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpatialExtent") + .IsRequired() + .HasColumnType("geometry"); + + b.HasKey("Id"); + + b.ToTable("Mandates"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Organisation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Organisations"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AuthIdentifier") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsAdmin") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("MandateOrganisation", b => + { + b.Property("MandatesId") + .HasColumnType("integer"); + + b.Property("OrganisationsId") + .HasColumnType("integer"); + + b.HasKey("MandatesId", "OrganisationsId"); + + b.HasIndex("OrganisationsId"); + + b.ToTable("MandateOrganisation"); + }); + + modelBuilder.Entity("OrganisationUser", b => + { + b.Property("OrganisationsId") + .HasColumnType("integer"); + + b.Property("UsersId") + .HasColumnType("integer"); + + b.HasKey("OrganisationsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("OrganisationUser"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Asset", b => + { + b.HasOne("Geopilot.Api.Models.Delivery", "Delivery") + .WithMany("Assets") + .HasForeignKey("DeliveryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Delivery"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Delivery", b => + { + b.HasOne("Geopilot.Api.Models.User", "DeclaringUser") + .WithMany("Deliveries") + .HasForeignKey("DeclaringUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Geopilot.Api.Models.Mandate", "Mandate") + .WithMany("Deliveries") + .HasForeignKey("MandateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Geopilot.Api.Models.Delivery", "PrecursorDelivery") + .WithMany() + .HasForeignKey("PrecursorDeliveryId"); + + b.Navigation("DeclaringUser"); + + b.Navigation("Mandate"); + + b.Navigation("PrecursorDelivery"); + }); + + modelBuilder.Entity("MandateOrganisation", b => + { + b.HasOne("Geopilot.Api.Models.Mandate", null) + .WithMany() + .HasForeignKey("MandatesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Geopilot.Api.Models.Organisation", null) + .WithMany() + .HasForeignKey("OrganisationsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OrganisationUser", b => + { + b.HasOne("Geopilot.Api.Models.Organisation", null) + .WithMany() + .HasForeignKey("OrganisationsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Geopilot.Api.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Delivery", b => + { + b.Navigation("Assets"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.Mandate", b => + { + b.Navigation("Deliveries"); + }); + + modelBuilder.Entity("Geopilot.Api.Models.User", b => + { + b.Navigation("Deliveries"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.cs b/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.cs new file mode 100644 index 00000000..4c8b3de7 --- /dev/null +++ b/src/Geopilot.Api/Migrations/20240528121852_RenameDeliveryMandate.cs @@ -0,0 +1,103 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Geopilot.Api.Migrations; + +/// +public partial class RenameDeliveryMandate : Migration +{ + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Deliveries_DeliveryMandates_DeliveryMandateId", + table: "Deliveries"); + + migrationBuilder.RenameColumn( + name: "DeliveryMandateId", + table: "Deliveries", + newName: "MandateId"); + + migrationBuilder.DropIndex( + name: "IX_Deliveries_DeliveryMandateId", + table: "Deliveries"); + + migrationBuilder.DropIndex( + name: "IX_DeliveryMandateOrganisation_OrganisationsId", + table: "DeliveryMandateOrganisation"); + + migrationBuilder.DropForeignKey( + name: "FK_DeliveryMandateOrganisation_DeliveryMandates_MandatesId", + table: "DeliveryMandateOrganisation"); + + migrationBuilder.DropForeignKey( + name: "FK_DeliveryMandateOrganisation_Organisations_OrganisationsId", + table: "DeliveryMandateOrganisation"); + + migrationBuilder.DropPrimaryKey( + name: "PK_DeliveryMandateOrganisation", + table: "DeliveryMandateOrganisation"); + + migrationBuilder.DropPrimaryKey( + name: "PK_DeliveryMandates", + table: "DeliveryMandates"); + + migrationBuilder.RenameTable( + name: "DeliveryMandates", + newName: "Mandates"); + + migrationBuilder.RenameTable( + name: "DeliveryMandateOrganisation", + newName: "MandateOrganisation"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Mandates", + table: "Mandates", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_MandateOrganisation", + table: "MandateOrganisation", + columns: new[] { "MandatesId", "OrganisationsId" }); + + migrationBuilder.AddForeignKey( + name: "FK_MandateOrganisation_Mandates_MandateId", + table: "MandateOrganisation", + column: "MandatesId", + principalTable: "Mandates", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_MandateOrganisation_Organisations_OrganisationId", + table: "MandateOrganisation", + column: "OrganisationsId", + principalTable: "Organisations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_MandateOrganisation_OrganisationId", + table: "MandateOrganisation", + column: "OrganisationsId"); + + migrationBuilder.AddForeignKey( + name: "FK_Deliveries_Mandates_MandateId", + table: "Deliveries", + column: "MandateId", + principalTable: "Mandates", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.CreateIndex( + name: "IX_Deliveries_MandateId", + table: "Deliveries", + column: "MandateId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + } +} diff --git a/src/Geopilot.Api/Migrations/ContextModelSnapshot.cs b/src/Geopilot.Api/Migrations/ContextModelSnapshot.cs index 17cdc6ec..b72df553 100644 --- a/src/Geopilot.Api/Migrations/ContextModelSnapshot.cs +++ b/src/Geopilot.Api/Migrations/ContextModelSnapshot.cs @@ -24,21 +24,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("DeliveryMandateOrganisation", b => - { - b.Property("MandatesId") - .HasColumnType("integer"); - - b.Property("OrganisationsId") - .HasColumnType("integer"); - - b.HasKey("MandatesId", "OrganisationsId"); - - b.HasIndex("OrganisationsId"); - - b.ToTable("DeliveryMandateOrganisation"); - }); - modelBuilder.Entity("Geopilot.Api.Models.Asset", b => { b.Property("Id") @@ -97,12 +82,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Deleted") .HasColumnType("boolean"); - b.Property("DeliveryMandateId") - .HasColumnType("integer"); - b.Property("JobId") .HasColumnType("uuid"); + b.Property("MandateId") + .HasColumnType("integer"); + b.Property("Partial") .HasColumnType("boolean"); @@ -113,14 +98,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("DeclaringUserId"); - b.HasIndex("DeliveryMandateId"); + b.HasIndex("MandateId"); b.HasIndex("PrecursorDeliveryId"); b.ToTable("Deliveries"); }); - modelBuilder.Entity("Geopilot.Api.Models.DeliveryMandate", b => + modelBuilder.Entity("Geopilot.Api.Models.Mandate", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -142,7 +127,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.ToTable("DeliveryMandates"); + b.ToTable("Mandates"); }); modelBuilder.Entity("Geopilot.Api.Models.Organisation", b => @@ -190,6 +175,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Users"); }); + modelBuilder.Entity("MandateOrganisation", b => + { + b.Property("MandatesId") + .HasColumnType("integer"); + + b.Property("OrganisationsId") + .HasColumnType("integer"); + + b.HasKey("MandatesId", "OrganisationsId"); + + b.HasIndex("OrganisationsId"); + + b.ToTable("MandateOrganisation"); + }); + modelBuilder.Entity("OrganisationUser", b => { b.Property("OrganisationsId") @@ -205,21 +205,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("OrganisationUser"); }); - modelBuilder.Entity("DeliveryMandateOrganisation", b => - { - b.HasOne("Geopilot.Api.Models.DeliveryMandate", null) - .WithMany() - .HasForeignKey("MandatesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Geopilot.Api.Models.Organisation", null) - .WithMany() - .HasForeignKey("OrganisationsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - modelBuilder.Entity("Geopilot.Api.Models.Asset", b => { b.HasOne("Geopilot.Api.Models.Delivery", "Delivery") @@ -239,9 +224,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Geopilot.Api.Models.DeliveryMandate", "DeliveryMandate") + b.HasOne("Geopilot.Api.Models.Mandate", "Mandate") .WithMany("Deliveries") - .HasForeignKey("DeliveryMandateId") + .HasForeignKey("MandateId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -251,11 +236,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DeclaringUser"); - b.Navigation("DeliveryMandate"); + b.Navigation("Mandate"); b.Navigation("PrecursorDelivery"); }); + modelBuilder.Entity("MandateOrganisation", b => + { + b.HasOne("Geopilot.Api.Models.Mandate", null) + .WithMany() + .HasForeignKey("MandatesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Geopilot.Api.Models.Organisation", null) + .WithMany() + .HasForeignKey("OrganisationsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("OrganisationUser", b => { b.HasOne("Geopilot.Api.Models.Organisation", null) @@ -276,7 +276,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("Assets"); }); - modelBuilder.Entity("Geopilot.Api.Models.DeliveryMandate", b => + modelBuilder.Entity("Geopilot.Api.Models.Mandate", b => { b.Navigation("Deliveries"); });