33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class tv_DogWalkers : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var viewName = "tv_DogWalkers";
|
|
var sql = @"CREATE FUNCTION tv_DogWalkers (@blockingAppUserId nvarchar(128)) RETURNS TABLE AS RETURN
|
|
SELECT DW.*
|
|
FROM vw_DogWalkers AS DW
|
|
LEFT OUTER JOIN AppUserBlocks AUB ON AUB.BlockedAppUserId = DW.Id AND AUB.BlockingAppUserId = @blockingAppUserId
|
|
WHERE ISNULL(AUB.Id, 0) = 0";
|
|
|
|
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_DogWalkers";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|