33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class tv_AppUserBlocksWithNames : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var viewName = "tv_AppUserBlocksWithNames";
|
|
var sql = @"CREATE FUNCTION tv_AppUserBlocksWithNames (@blockingAppUserId nvarchar(128)) RETURNS TABLE AS RETURN
|
|
Select AUB.*, AU.Type, AU.FirstName, AU.LastName, AU.Photo, AU.Address_City AS LocationHint, AU.Location, AU.Locked, AU.Deleted
|
|
FROM AppUserBlocks AUB
|
|
LEFT JOIN AppUsers AU ON AU.Id = AUB.BlockedAppUserId
|
|
WHERE AUB.BlockingAppUserId = @blockingAppUserId";
|
|
|
|
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_AppUserBlocksWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|