132 lines
5.2 KiB
C#
132 lines
5.2 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class VoucherCampaignWithNamesAdded : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmountUsed",
|
|
table: "VoucherUsages",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "VoucherUsages",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "Vouchers",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "BudgetUsed",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "Budget",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,4)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,2)");
|
|
|
|
var viewName = "tv_VoucherCampignsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_VoucherCampignsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.VoucherCampaigns.*,
|
|
C.Name AS CustomerName,
|
|
Isnull(JSON_VALUE(dbo.VoucherCampaigns.NameLocalized, '$.' + @language), JSON_VALUE(dbo.VoucherCampaigns.NameLocalized, '$.' + @fallback)) AS Name,
|
|
JSON_VALUE(dbo.VoucherCampaigns.ImageLanguageLocalized, '$.' + @language) AS ImageLanguage,
|
|
JSON_VALUE(dbo.VoucherCampaigns.UrlLanguageLocalized, '$.' + @language) AS UrlLanguage
|
|
FROM dbo.VoucherCampaigns
|
|
LEFT JOIN dbo.tv_CustomersWithNames(@language, @fallback) C ON dbo.VoucherCampaigns.CustomerId = C.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");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmountUsed",
|
|
table: "VoucherUsages",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "VoucherUsages",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "Vouchers",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "VoucherAmmount",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "BudgetUsed",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
migrationBuilder.AlterColumn<decimal>(
|
|
name: "Budget",
|
|
table: "VoucherCampaigns",
|
|
type: "decimal(18,2)",
|
|
nullable: false,
|
|
oldClrType: typeof(decimal),
|
|
oldType: "decimal(18,4)");
|
|
|
|
var viewName = "tv_VoucherCampignsWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|