feat: add geography entities with countries, states and cities

This commit is contained in:
masoodafar-web
2025-12-18 00:43:55 +03:30
parent 26e1243cfe
commit ead0cf4235
40 changed files with 5386 additions and 7 deletions
@@ -0,0 +1,146 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddGeographyEntities : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "GMS");
migrationBuilder.CreateTable(
name: "Countries",
schema: "GMS",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ExternalId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Iso3 = table.Column<string>(type: "nvarchar(3)", maxLength: 3, nullable: false),
Iso2 = table.Column<string>(type: "nvarchar(2)", maxLength: 2, nullable: false),
NumericCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
PhoneCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
Capital = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Currency = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
CurrencyName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
CurrencySymbol = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
Tld = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
Native = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Region = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Subregion = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Latitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Longitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Emoji = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
EmojiU = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Countries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "States",
schema: "GMS",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ExternalId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
StateCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
Latitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Longitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Type = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Native = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false, defaultValue: ""),
CountryId = table.Column<long>(type: "bigint", nullable: false),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_States", x => x.Id);
table.ForeignKey(
name: "FK_States_Countries_CountryId",
column: x => x.CountryId,
principalSchema: "GMS",
principalTable: "Countries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Cities",
schema: "GMS",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ExternalId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
Latitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Longitude = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Native = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false, defaultValue: ""),
StateId = table.Column<long>(type: "bigint", nullable: false),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cities", x => x.Id);
table.ForeignKey(
name: "FK_Cities_States_StateId",
column: x => x.StateId,
principalSchema: "GMS",
principalTable: "States",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Cities_StateId",
schema: "GMS",
table: "Cities",
column: "StateId");
migrationBuilder.CreateIndex(
name: "IX_States_CountryId",
schema: "GMS",
table: "States",
column: "CountryId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Cities",
schema: "GMS");
migrationBuilder.DropTable(
name: "States",
schema: "GMS");
migrationBuilder.DropTable(
name: "Countries",
schema: "GMS");
}
}
}
@@ -1014,6 +1014,256 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.ToTable("FactorDetails", "CMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.City", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<long>("ExternalId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<string>("Latitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Longitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<string>("Native")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)")
.HasDefaultValue("");
b.Property<long>("StateId")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("StateId")
.HasDatabaseName("IX_Cities_StateId");
b.ToTable("Cities", "GMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.Country", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<string>("Capital")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<string>("Currency")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("CurrencyName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("CurrencySymbol")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Emoji")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("EmojiU")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<long>("ExternalId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Iso2")
.IsRequired()
.HasMaxLength(2)
.HasColumnType("nvarchar(2)");
b.Property<string>("Iso3")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("nvarchar(3)");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<string>("Latitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Longitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<string>("Native")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<string>("NumericCode")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("PhoneCode")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Region")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("Subregion")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("Tld")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.HasKey("Id");
b.ToTable("Countries", "GMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.State", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<long>("CountryId")
.HasColumnType("bigint");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<long>("ExternalId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<string>("Latitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Longitude")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<string>("Native")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(500)
.HasColumnType("nvarchar(500)")
.HasDefaultValue("");
b.Property<string>("StateCode")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.HasKey("Id");
b.HasIndex("CountryId")
.HasDatabaseName("IX_States_CountryId");
b.ToTable("States", "GMS");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipHistory", b =>
{
b.Property<long>("Id")
@@ -2789,6 +3039,28 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("Product");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.City", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.Geography.State", "State")
.WithMany("Cities")
.HasForeignKey("StateId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("State");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.State", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.Geography.Country", "Country")
.WithMany("States")
.HasForeignKey("CountryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Country");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipHistory", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubMembership", "ClubMembership")
@@ -3149,6 +3421,16 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("ShoppingCarts");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.Country", b =>
{
b.Navigation("States");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Geography.State", b =>
{
b.Navigation("Cities");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Package", b =>
{
b.Navigation("UserOrders");