76 lines
4.1 KiB
C#
76 lines
4.1 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class ListingImage2Added : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "Image2",
|
|
table: "Listings",
|
|
type: "nvarchar(500)",
|
|
maxLength: 500,
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "Image2LanguageLocalized",
|
|
table: "Listings",
|
|
type: "nvarchar(max)",
|
|
nullable: true);
|
|
|
|
var viewName = "tv_ListingsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_ListingsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.Listings.*,
|
|
C.Name AS CustomerName,
|
|
BR.Name AS BranchName,
|
|
BR.OnlineStatus AS BranchOnlineStatus,
|
|
Isnull(JSON_VALUE(dbo.Listings.NameLocalized, '$.' + @language), JSON_VALUE(dbo.Listings.NameLocalized, '$.' + @fallback)) AS Name,
|
|
Isnull(JSON_VALUE(dbo.Listings.DescriptionLocalized, '$.' + @language), JSON_VALUE(dbo.Listings.DescriptionLocalized, '$.' + @fallback)) AS Description,
|
|
JSON_VALUE(dbo.Listings.ImageLanguageLocalized, '$.' + @language) AS ImageLanguage,
|
|
JSON_VALUE(dbo.Listings.Image2LanguageLocalized, '$.' + @language) AS Image2Language,
|
|
JSON_VALUE(dbo.Listings.UrlLanguageLocalized, '$.' + @language) AS UrlLanguage
|
|
FROM dbo.Listings
|
|
LEFT JOIN dbo.tv_CustomersWithNames(@language, @fallback) C ON dbo.Listings.CustomerId = C.Id
|
|
LEFT JOIN dbo.tv_BranchesWithNames(@language, @fallback) BR ON dbo.Listings.BranchId = BR.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.DropColumn(
|
|
name: "Image2",
|
|
table: "Listings");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "Image2LanguageLocalized",
|
|
table: "Listings");
|
|
|
|
var viewName = "tv_ListingsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_ListingsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.Listings.*,
|
|
C.Name AS CustomerName,
|
|
BR.Name AS BranchName,
|
|
BR.OnlineStatus AS BranchOnlineStatus,
|
|
Isnull(JSON_VALUE(dbo.Listings.NameLocalized, '$.' + @language), JSON_VALUE(dbo.Listings.NameLocalized, '$.' + @fallback)) AS Name,
|
|
Isnull(JSON_VALUE(dbo.Listings.DescriptionLocalized, '$.' + @language), JSON_VALUE(dbo.Listings.DescriptionLocalized, '$.' + @fallback)) AS Description,
|
|
JSON_VALUE(dbo.Listings.ImageLanguageLocalized, '$.' + @language) AS ImageLanguage,
|
|
JSON_VALUE(dbo.Listings.UrlLanguageLocalized, '$.' + @language) AS UrlLanguage
|
|
FROM dbo.Listings
|
|
LEFT JOIN dbo.tv_CustomersWithNames(@language, @fallback) C ON dbo.Listings.CustomerId = C.Id
|
|
LEFT JOIN dbo.tv_BranchesWithNames(@language, @fallback) BR ON dbo.Listings.BranchId = BR.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");
|
|
}
|
|
}
|
|
}
|