using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace gehGassi.Persistence.Migrations { /// public partial class CustomerMangopayAdded : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "MangopayAddress", table: "Customers", type: "nvarchar(max)", nullable: true); migrationBuilder.AddColumn( name: "MangopayCompanyName", table: "Customers", type: "nvarchar(256)", maxLength: 256, nullable: true); migrationBuilder.AddColumn( name: "MangopayContactBirthdate", table: "Customers", type: "date", nullable: true); migrationBuilder.AddColumn( name: "MangopayContactEmail", table: "Customers", type: "nvarchar(255)", maxLength: 255, nullable: true); migrationBuilder.AddColumn( name: "MangopayContactFirstName", table: "Customers", type: "nvarchar(100)", maxLength: 100, nullable: true); migrationBuilder.AddColumn( name: "MangopayContactLastName", table: "Customers", type: "nvarchar(100)", maxLength: 100, nullable: true); migrationBuilder.AddColumn( name: "MangopayContactMainResidenceCode", table: "Customers", type: "nvarchar(2)", maxLength: 2, nullable: true); migrationBuilder.AddColumn( name: "MangopayContactNationality", table: "Customers", type: "nvarchar(2)", maxLength: 2, nullable: true); migrationBuilder.AddColumn( name: "MangopayEmail", table: "Customers", type: "nvarchar(255)", maxLength: 255, nullable: true); migrationBuilder.AddColumn( name: "MangopayIdCreated", table: "Customers", type: "bit", nullable: false, defaultValue: false); migrationBuilder.AddColumn( name: "MangopayPaymentId", table: "Customers", type: "nvarchar(255)", maxLength: 255, nullable: true); migrationBuilder.AddColumn( name: "MangopayRegistrationNumber", table: "Customers", type: "nvarchar(50)", maxLength: 50, nullable: true); var viewName = "tv_CustomersWithNames"; var sql = @"CREATE FUNCTION tv_CustomersWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN SELECT dbo.Customers.*, dbo.CustomerTypes.Name AS TypeName, BN.Name AS BranchName FROM dbo.Customers LEFT JOIN dbo.CustomerTypes ON dbo.Customers.TypeId = dbo.CustomerTypes.Id LEFT JOIN dbo.tv_BranchesWithNames(@language, @fallback) BN ON dbo.Customers.BranchId = BN.Id"; migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO"); migrationBuilder.Sql($"{sql} {Environment.NewLine} GO"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropColumn( name: "MangopayAddress", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayCompanyName", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactBirthdate", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactEmail", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactFirstName", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactLastName", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactMainResidenceCode", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayContactNationality", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayEmail", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayIdCreated", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayPaymentId", table: "Customers"); migrationBuilder.DropColumn( name: "MangopayRegistrationNumber", table: "Customers"); var viewName = "tv_CustomersWithNames"; var sql = @"CREATE FUNCTION tv_CustomersWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN SELECT dbo.Customers.*, dbo.CustomerTypes.Name AS TypeName, BN.Name AS BranchName FROM dbo.Customers LEFT JOIN dbo.CustomerTypes ON dbo.Customers.TypeId = dbo.CustomerTypes.Id LEFT JOIN dbo.tv_BranchesWithNames(@language, @fallback) BN ON dbo.Customers.BranchId = BN.Id"; migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO"); migrationBuilder.Sql($"{sql} {Environment.NewLine} GO"); } } }