35 lines
1.6 KiB
C#
35 lines
1.6 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class tv_WalkComplaintsWithNames : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var viewName = "tv_WalkComplaintsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_WalkComplaintsWithNames() RETURNS TABLE AS RETURN
|
|
SELECT WC.*,
|
|
WN.DogWalkerName AS DogWalkerName, WN.DogWalkerPhoto AS DogWalkerPhoto, WN.DogOwnerName AS DogOwnerName, WN.DogOwnerPhoto AS DogOwnerPhoto,
|
|
WN.Start AS WalkStart, WN.[End] AS WalkEnd, WN.PickupAddress_CountryCode AS PickupAddress_CountryCode, WN.Price AS WalkPrice,
|
|
WN.Type AS WalkType, WN.ServiceType AS WalkServiceType
|
|
FROM WalkComplaints WC
|
|
LEFT JOIN dbo.tv_WalksWithNames() WN ON WC.WalkId = WN.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)
|
|
{
|
|
var viewName = "tv_WalkComplaintsWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|