76 lines
3.4 KiB
C#
76 lines
3.4 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using NetTopologySuite.Geometries;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
public partial class BannerLocation : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropColumn(
|
|
name: "Lat",
|
|
table: "Banners");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "Lng",
|
|
table: "Banners");
|
|
|
|
migrationBuilder.AddColumn<Point>(
|
|
name: "Location",
|
|
table: "Banners",
|
|
type: "geography",
|
|
nullable: true);
|
|
|
|
var viewName = "tv_BannersWithNames";
|
|
var sql = @"CREATE FUNCTION tv_BannersWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.Banners.*,
|
|
C.Name AS CustomerName,
|
|
Isnull(JSON_VALUE(dbo.Banners.NameLocalized, '$.' + @language), JSON_VALUE(dbo.Banners.NameLocalized, '$.' + @fallback)) AS Name,
|
|
JSON_VALUE(dbo.Banners.ImageLanguageLocalized, '$.' + @language) AS ImageLanguage,
|
|
JSON_VALUE(dbo.Banners.UrlLanguageLocalized, '$.' + @language) AS UrlLanguage
|
|
FROM dbo.Banners
|
|
LEFT JOIN dbo.tv_CustomersWithNames(@language, @fallback) C ON dbo.Banners.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");
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropColumn(
|
|
name: "Location",
|
|
table: "Banners");
|
|
|
|
migrationBuilder.AddColumn<double>(
|
|
name: "Lat",
|
|
table: "Banners",
|
|
type: "float",
|
|
nullable: false,
|
|
defaultValue: 0.0);
|
|
|
|
migrationBuilder.AddColumn<double>(
|
|
name: "Lng",
|
|
table: "Banners",
|
|
type: "float",
|
|
nullable: false,
|
|
defaultValue: 0.0);
|
|
|
|
var viewName = "tv_BannersWithNames";
|
|
var sql = @"CREATE FUNCTION tv_BannersWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.Banners.*,
|
|
C.Name AS CustomerName,
|
|
Isnull(JSON_VALUE(dbo.Banners.NameLocalized, '$.' + @language), JSON_VALUE(dbo.Banners.NameLocalized, '$.' + @fallback)) AS Name,
|
|
JSON_VALUE(dbo.Banners.ImageLanguageLocalized, '$.' + @language) AS ImageLanguage,
|
|
JSON_VALUE(dbo.Banners.UrlLanguageLocalized, '$.' + @language) AS UrlLanguage
|
|
FROM dbo.Banners
|
|
LEFT JOIN dbo.tv_CustomersWithNames(@language, @fallback) C ON dbo.Banners.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");
|
|
}
|
|
}
|
|
}
|