gehgassi_backend/gehGassi.Persistence/Migrations/20231108082745_AppVersionAdded.cs

61 lines
3.2 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace gehGassi.Persistence.Migrations
{
/// <inheritdoc />
public partial class AppVersionAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AppVersions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Platform = table.Column<int>(type: "int", nullable: false),
Major = table.Column<int>(type: "int", nullable: false),
Minor = table.Column<int>(type: "int", nullable: false),
Build = table.Column<int>(type: "int", nullable: true),
Revision = table.Column<int>(type: "int", nullable: true),
Version = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
IsCurrent = table.Column<bool>(type: "bit", nullable: false),
IsMandatory = table.Column<bool>(type: "bit", nullable: false),
ReleaseTitleLocalized = table.Column<string>(type: "nvarchar(max)", nullable: true),
ReleaseNotesLocalized = table.Column<string>(type: "nvarchar(max)", nullable: true),
ReleaseDate = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
LastUpdate = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppVersions", x => x.Id);
});
var viewName = "tv_AppVersionsWithNames";
var sql = @"CREATE FUNCTION tv_AppVersionsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
SELECT dbo.AppVersions.*,
Isnull(JSON_VALUE(dbo.AppVersions.ReleaseTitleLocalized, '$.' + @language), JSON_VALUE(dbo.AppVersions.ReleaseTitleLocalized, '$.' + @fallback)) AS ReleaseTitle,
Isnull(JSON_VALUE(dbo.AppVersions.ReleaseNotesLocalized, '$.' + @language), JSON_VALUE(dbo.AppVersions.ReleaseNotesLocalized, '$.' + @fallback)) AS ReleaseNotes
FROM dbo.AppVersions";
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_AppVersionsWithNames";
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
migrationBuilder.DropTable(
name: "AppVersions");
}
}
}