30 lines
1.3 KiB
C#
30 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
public partial class tv_PublicWalkResponseWithNamesAdded : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var viewName = "tv_PublicWalkResponseWithNames";
|
|
var sql = @"CREATE FUNCTION tv_PublicWalkResponseWithNames() RETURNS TABLE AS RETURN
|
|
SELECT PWR.*,
|
|
CONCAT(DW.FirstName, ' ', DW.LastName) AS DogWalkerName, DW.Photo AS DogWalkerPhoto
|
|
FROM PublicWalkResponses PWR
|
|
LEFT JOIN AppUsers DW ON PWR.DogWalkerId = DW.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)
|
|
{
|
|
var viewName = "tv_PublicWalkResponseWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|