36 lines
1.8 KiB
C#
36 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class tv_AppUserSubscriptionsWithNamesAdded : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
var viewName = "tv_AppUserSubscriptionsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_AppUserSubscriptionsWithNames(@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT AUS.*,
|
|
CONCAT(A.FirstName, A.LastName, ' ') AS AppUserName, A.Photo AS AppUserPhoto,
|
|
S.Code AS SubscriptionCode, S.Length AS SubscriptionLength, S.Price AS SubscriptionPrice, S.AppMode AS SubscriptionAppMode,
|
|
Isnull(JSON_VALUE(S.NameLocalized, '$.' + @language), JSON_VALUE(S.NameLocalized, '$.' + @fallback)) AS SubscriptionName
|
|
FROM AppUserSubscriptions AUS
|
|
LEFT JOIN Subscriptions S ON S.Id = AUS.SubscriptionId
|
|
LEFT JOIN AppUsers A ON A.Id = AUS.AppUserId";
|
|
|
|
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_AppUserSubscriptionsWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
}
|
|
}
|
|
}
|