gehgassi_backend/gehGassi.Persistence/Migrations/20221108185811_vw_DogWalkersTermsAdded.cs

35 lines
1.7 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using System;
#nullable disable
namespace gehGassi.Persistence.Migrations
{
public partial class vw_DogWalkersTermsAdded : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var viewName = "vw_DogWalkers";
var sql = @"Select AU.*, DP.Radius, DP.About, DP.AllowedRequests, DP.PuppyAllowed, DP.DifficultAllowed, DP.AggressionLevel, DP.AcceptedSize, DP.PriceWalk, DP.PriceDay, DP.PriceSitting, DP.NotAvailable, DP.NotAvailableInfo
from AppUsers AU
JOIN DogWalkerProfiles DP ON DP.Id = AU.Id
WHERE AU.Type != 10";
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.views WHERE Name = '{viewName}')) BEGIN DROP VIEW [dbo].[{viewName}] END {Environment.NewLine} GO");
migrationBuilder.Sql($"CREATE VIEW [dbo].[{viewName}] AS {sql} {Environment.NewLine} GO");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
var viewName = "vw_DogWalkers";
var sql = @"Select AU.*, DP.Radius, DP.About, DP.AllowedRequests, DP.PuppyAllowed, DP.DifficultAllowed, DP.AggressionLevel, DP.AcceptedSize, DP.PriceWalk, DP.PriceDay, DP.PriceSitting, DP.NotAvailable, DP.NotAvailableInfo
from AppUsers AU
JOIN DogWalkerProfiles DP ON DP.Id = AU.Id
WHERE AU.Type != 10";
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.views WHERE Name = '{viewName}')) BEGIN DROP VIEW [dbo].[{viewName}] END {Environment.NewLine} GO");
migrationBuilder.Sql($"CREATE VIEW [dbo].[{viewName}] AS {sql} {Environment.NewLine} GO");
}
}
}