Skip to content

Commit

Permalink
feat(countries): Add table country_long_names to schema (#343)
Browse files Browse the repository at this point in the history
* add new table country_long_names
* adjust seeding data
* adjust existing queries
---------
Co-authored-by: Norbert Truchsess <norbert.truchsess@t-online.de>
Reviewed-by: Norbert Truchsess <norbert.truchsess@t-online.de>
Reviewed-by: Phil Schneider <info@philschneider.de>
  • Loading branch information
AnuragNagpure authored Nov 29, 2023
1 parent 2c6c77f commit 4c2f39e
Show file tree
Hide file tree
Showing 14 changed files with 11,711 additions and 774 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public record ParticipantDetails(
[property: JsonPropertyName("bpn")] string? Bpn,
[property: JsonPropertyName("region")] string? Region,
[property: JsonPropertyName("zipCode")] string? ZipCode,
[property: JsonPropertyName("country")] string Country,
[property: JsonPropertyName("country")] string? Country,
[property: JsonPropertyName("countryAlpha2Code")] string CountryAlpha2Code
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void DeleteInvitations(IEnumerable<Guid> invitationIds) =>
data.Company.AddressId,
data.Company.Address!.Streetname,
data.Company.Address.City,
data.Company.Address.Country!.CountryNameDe,
data.Company.Address.Country!.CountryLongNames.Where(cln => cln.ShortName == "de").Select(cln => cln.LongName).SingleOrDefault(),
data.Company.CompanyIdentifiers.Select(x => x.UniqueIdentifierId),
data.Company.CompanyAssignedRoles.Select(companyAssignedRole => companyAssignedRole.CompanyRoleId)),
data.Consents.Select(consent =>
Expand Down Expand Up @@ -262,7 +262,7 @@ public IQueryable<CompanyApplication> GetAllCompanyApplicationsDetailsQuery(stri
companyApplication.Company.Address.Streetadditional,
companyApplication.Company.Address.Streetnumber,
companyApplication.Company.Address.Zipcode,
companyApplication.Company.Address.Country!.CountryNameDe,
companyApplication.Company.Address.Country!.CountryLongNames.Where(cln => cln.ShortName == "de").Select(cln => cln.LongName).SingleOrDefault(),
companyApplication.Company.CompanyAssignedRoles.SelectMany(assigned =>
assigned.CompanyRole!.AgreementAssignedCompanyRoles.Select(x =>
new AgreementsData(
Expand Down Expand Up @@ -359,7 +359,7 @@ public IQueryable<CompanyApplication> GetAllCompanyApplicationsDetailsQuery(stri
ca.Company.BusinessPartnerNumber,
ca.Address.Region,
ca.Address.Zipcode,
ca.Address.Country!.CountryNameEn,
ca.Address.Country!.CountryLongNames.Where(cln => cln.ShortName == "en").Select(cln => cln.LongName).SingleOrDefault(),
ca.Address.CountryAlpha2Code),
ca.CompanyIdentifiers.Select(ci => new UniqueIdData(ci.UniqueIdentifier!.Label, ci.Value))))
.SingleOrDefaultAsync();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/********************************************************************************
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.Migrations.Migrations
{
/// <inheritdoc />
public partial class CPLP3451CountryLongName : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "country_name_de",
schema: "portal",
table: "countries");

migrationBuilder.DropColumn(
name: "country_name_en",
schema: "portal",
table: "countries");

migrationBuilder.CreateTable(
name: "country_long_names",
schema: "portal",
columns: table => new
{
alpha2code = table.Column<string>(type: "character(2)", maxLength: 2, nullable: false),
short_name = table.Column<string>(type: "character(2)", maxLength: 2, nullable: false),
long_name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_country_long_names", x => new { x.alpha2code, x.short_name });
table.ForeignKey(
name: "fk_country_long_names_countries_country_alpha2code",
column: x => x.alpha2code,
principalSchema: "portal",
principalTable: "countries",
principalColumn: "alpha2code");
table.ForeignKey(
name: "fk_country_long_names_languages_language_temp_id2",
column: x => x.short_name,
principalSchema: "portal",
principalTable: "languages",
principalColumn: "short_name");
});

migrationBuilder.CreateIndex(
name: "ix_country_long_names_short_name",
schema: "portal",
table: "country_long_names",
column: "short_name");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "country_long_names",
schema: "portal");

migrationBuilder.AddColumn<string>(
name: "country_name_de",
schema: "portal",
table: "countries",
type: "character varying(255)",
maxLength: 255,
nullable: false,
defaultValue: "");

migrationBuilder.AddColumn<string>(
name: "country_name_en",
schema: "portal",
table: "countries",
type: "character varying(255)",
maxLength: 255,
nullable: false,
defaultValue: "");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3943,18 +3943,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsFixedLength()
.HasAnnotation("Relational:JsonPropertyName", "alpha3code");
b.Property<string>("CountryNameDe")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("country_name_de");
b.Property<string>("CountryNameEn")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("country_name_en");
b.HasKey("Alpha2Code")
.HasName("pk_countries");
Expand Down Expand Up @@ -3989,6 +3977,33 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("country_assigned_identifiers", "portal");
});

modelBuilder.Entity("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.CountryLongName", b =>
{
b.Property<string>("Alpha2Code")
.HasMaxLength(2)
.HasColumnType("character(2)")
.HasColumnName("alpha2code")
.HasAnnotation("Relational:JsonPropertyName", "alpha2code");
b.Property<string>("ShortName")
.HasMaxLength(2)
.HasColumnType("character(2)")
.HasColumnName("short_name");
b.Property<string>("LongName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("long_name");
b.HasKey("Alpha2Code", "ShortName")
.HasName("pk_country_long_names");
b.HasIndex("ShortName")
.HasDatabaseName("ix_country_long_names_short_name");
b.ToTable("country_long_names", "portal");
});

modelBuilder.Entity("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.Document", b =>
{
b.Property<Guid>("Id")
Expand Down Expand Up @@ -7499,6 +7514,25 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("UniqueIdentifier");
});

modelBuilder.Entity("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.CountryLongName", b =>
{
b.HasOne("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.Country", "Country")
.WithMany("CountryLongNames")
.HasForeignKey("Alpha2Code")
.IsRequired()
.HasConstraintName("fk_country_long_names_countries_country_alpha2code");
b.HasOne("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.Language", "Language")
.WithMany("CountryLongNames")
.HasForeignKey("ShortName")
.IsRequired()
.HasConstraintName("fk_country_long_names_languages_language_temp_id2");
b.Navigation("Country");
b.Navigation("Language");
});

modelBuilder.Entity("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.Document", b =>
{
b.HasOne("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.CompanyUser", "CompanyUser")
Expand Down Expand Up @@ -8455,6 +8489,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("Connectors");
b.Navigation("CountryAssignedIdentifiers");
b.Navigation("CountryLongNames");
});

modelBuilder.Entity("Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities.Document", b =>
Expand Down Expand Up @@ -8536,6 +8572,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("CompanyRoleDescriptions");
b.Navigation("CountryLongNames");
b.Navigation("LanguageLongNameLanguages");
b.Navigation("LanguageLongNames");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
await SeedTable<ConsentAssignedOffer>("consent_assigned_offers", x => new { x.OfferId, x.ConsentId }, cancellationToken).ConfigureAwait(false);
await SeedTable<ConsentAssignedOfferSubscription>("consent_assigned_offer_subscriptions", x => new { x.OfferSubscriptionId, x.ConsentId }, cancellationToken).ConfigureAwait(false);
await SeedTable<ConnectorAssignedOfferSubscription>("connector_assigned_offer_subscriptions", x => new { x.ConnectorId, x.OfferSubscriptionId }, cancellationToken).ConfigureAwait(false);
await SeedTable<CountryLongName>("country_long_names", x => new { x.Alpha2Code, x.ShortName }, cancellationToken).ConfigureAwait(false);
await SeedTable<Country>("countries", x => x.Alpha2Code, cancellationToken).ConfigureAwait(false);
await SeedTable<OfferAssignedDocument>("offer_assigned_documents", x => new { x.OfferId, x.DocumentId }, cancellationToken).ConfigureAwait(false);
await SeedTable<IamIdentityProvider>("iam_identity_providers", x => x.IamIdpAlias, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ await SeedTable<UserRoleCollectionDescription>(
await SeedTable<Country>(
"countries",
x => x.Alpha2Code,
x => x.dbEntity.Alpha3Code != x.dataEntity.Alpha3Code || x.dbEntity.CountryNameDe != x.dataEntity.CountryNameDe || x.dbEntity.CountryNameEn != x.dataEntity.CountryNameEn,
x => x.dbEntity.Alpha3Code != x.dataEntity.Alpha3Code,
(dbEntry, entry) =>
{
dbEntry.Alpha3Code = entry.Alpha3Code;
dbEntry.CountryNameDe = entry.CountryNameDe;
dbEntry.CountryNameEn = entry.CountryNameEn;
}, cancellationToken).ConfigureAwait(false);

await SeedTable<CompanyIdentifier>("company_identifiers",
Expand Down
Loading

0 comments on commit 4c2f39e

Please sign in to comment.