using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace AMREZ.EOP.Infrastructures.Migrations { /// public partial class AddCustomer : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "addresses", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Line1 = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Line2 = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), Village = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), Soi = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), Road = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), Subdistrict = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), District = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), Province = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), PostalCode = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), CountryCode = table.Column(type: "character varying(2)", maxLength: 2, nullable: false), Verified = table.Column(type: "boolean", nullable: false), GeoLat = table.Column(type: "double precision", nullable: true), GeoLng = table.Column(type: "double precision", nullable: true), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_addresses", x => x.Id); table.UniqueConstraint("AK_addresses_tenant_id_Id", x => new { x.tenant_id, x.Id }); table.CheckConstraint("ck_addresses_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_addresses_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); }); migrationBuilder.CreateTable( name: "customer_profiles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), DisplayName = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Status = table.Column(type: "integer", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_customer_profiles", x => x.Id); table.UniqueConstraint("AK_customer_profiles_tenant_id_Id", x => new { x.tenant_id, x.Id }); table.CheckConstraint("ck_customer_profiles_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_customer_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); }); migrationBuilder.CreateTable( name: "customer_addresses", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerProfileId = table.Column(type: "uuid", nullable: false), AddressId = table.Column(type: "uuid", nullable: false), Label = table.Column(type: "integer", nullable: false), IsDefault = table.Column(type: "boolean", nullable: false, defaultValue: false), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_customer_addresses", x => x.Id); table.CheckConstraint("ck_customer_addresses_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_customer_addresses_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); table.ForeignKey( name: "FK_customer_addresses_addresses_tenant_id_AddressId", columns: x => new { x.tenant_id, x.AddressId }, principalTable: "addresses", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_customer_addresses_customer_profiles_tenant_id_CustomerProf~", columns: x => new { x.tenant_id, x.CustomerProfileId }, principalTable: "customer_profiles", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "customer_contacts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerProfileId = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), Value = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), IsPrimary = table.Column(type: "boolean", nullable: false, defaultValue: false), IsVerified = table.Column(type: "boolean", nullable: false, defaultValue: false), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_customer_contacts", x => x.Id); table.CheckConstraint("ck_customer_contacts_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_customer_contacts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); table.ForeignKey( name: "FK_customer_contacts_customer_profiles_tenant_id_CustomerProfi~", columns: x => new { x.tenant_id, x.CustomerProfileId }, principalTable: "customer_profiles", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "customer_tags", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerProfileId = table.Column(type: "uuid", nullable: false), Tag = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_customer_tags", x => x.Id); table.CheckConstraint("ck_customer_tags_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_customer_tags_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); table.ForeignKey( name: "FK_customer_tags_customer_profiles_tenant_id_CustomerProfileId", columns: x => new { x.tenant_id, x.CustomerProfileId }, principalTable: "customer_profiles", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "organization_profiles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerProfileId = table.Column(type: "uuid", nullable: false), LegalNameTh = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), LegalNameEn = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), RegistrationNo = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), TaxId13 = table.Column(type: "character varying(13)", maxLength: 13, nullable: true), BranchCode = table.Column(type: "character varying(5)", maxLength: 5, nullable: true), CompanyType = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_organization_profiles", x => x.Id); table.CheckConstraint("ck_organization_profiles_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_organization_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); table.ForeignKey( name: "FK_organization_profiles_customer_profiles_tenant_id_CustomerP~", columns: x => new { x.tenant_id, x.CustomerProfileId }, principalTable: "customer_profiles", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "person_profiles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerProfileId = table.Column(type: "uuid", nullable: false), Prefix = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), FirstNameTh = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), LastNameTh = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), FirstNameEn = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), LastNameEn = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), BirthDate = table.Column(type: "timestamp with time zone", nullable: true), NationalId = table.Column(type: "character varying(13)", maxLength: 13, nullable: true), PassportNo = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_person_profiles", x => x.Id); table.CheckConstraint("ck_person_profiles_tenant_not_null", "tenant_id is not null"); table.CheckConstraint("ck_person_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'"); table.ForeignKey( name: "FK_person_profiles_customer_profiles_tenant_id_CustomerProfile~", columns: x => new { x.tenant_id, x.CustomerProfileId }, principalTable: "customer_profiles", principalColumns: new[] { "tenant_id", "Id" }, onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_addresses_tenant_id", table: "addresses", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_customer_addresses_tenant_id", table: "customer_addresses", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_customer_addresses_tenant_id_AddressId", table: "customer_addresses", columns: new[] { "tenant_id", "AddressId" }); migrationBuilder.CreateIndex( name: "IX_customer_addresses_tenant_id_CustomerProfileId_Label", table: "customer_addresses", columns: new[] { "tenant_id", "CustomerProfileId", "Label" }); migrationBuilder.CreateIndex( name: "ux_default_customer_address_per_label", table: "customer_addresses", columns: new[] { "tenant_id", "CustomerProfileId", "Label", "IsDefault" }, unique: true, filter: "\"IsDefault\" = TRUE"); migrationBuilder.CreateIndex( name: "IX_customer_contacts_tenant_id", table: "customer_contacts", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_customer_contacts_tenant_id_CustomerProfileId_Type", table: "customer_contacts", columns: new[] { "tenant_id", "CustomerProfileId", "Type" }); migrationBuilder.CreateIndex( name: "ux_customer_contact_primary_per_type", table: "customer_contacts", columns: new[] { "tenant_id", "CustomerProfileId", "Type", "IsPrimary" }, unique: true, filter: "\"IsPrimary\" = TRUE"); migrationBuilder.CreateIndex( name: "IX_customer_profiles_tenant_id", table: "customer_profiles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_customer_profiles_tenant_id_DisplayName", table: "customer_profiles", columns: new[] { "tenant_id", "DisplayName" }); migrationBuilder.CreateIndex( name: "IX_customer_tags_tenant_id", table: "customer_tags", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_customer_tags_tenant_id_CustomerProfileId_Tag", table: "customer_tags", columns: new[] { "tenant_id", "CustomerProfileId", "Tag" }, unique: true); migrationBuilder.CreateIndex( name: "IX_organization_profiles_tenant_id", table: "organization_profiles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_organization_profiles_tenant_id_CustomerProfileId", table: "organization_profiles", columns: new[] { "tenant_id", "CustomerProfileId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_organization_profiles_tenant_id_TaxId13_BranchCode", table: "organization_profiles", columns: new[] { "tenant_id", "TaxId13", "BranchCode" }, unique: true, filter: "\"TaxId13\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_person_profiles_tenant_id", table: "person_profiles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_person_profiles_tenant_id_CustomerProfileId", table: "person_profiles", columns: new[] { "tenant_id", "CustomerProfileId" }, unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "customer_addresses"); migrationBuilder.DropTable( name: "customer_contacts"); migrationBuilder.DropTable( name: "customer_tags"); migrationBuilder.DropTable( name: "organization_profiles"); migrationBuilder.DropTable( name: "person_profiles"); migrationBuilder.DropTable( name: "addresses"); migrationBuilder.DropTable( name: "customer_profiles"); } } }