58 lines
2.9 KiB
C#
58 lines
2.9 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class FaqAdded : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Faqs",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
|
|
Title = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
|
Order = table.Column<int>(type: "int", nullable: false),
|
|
QuestionLocalized = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
AnswerLocalized = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
OnlineStatus = table.Column<int>(type: "int", nullable: false),
|
|
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
|
|
Index = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
Version = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: true),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
|
|
Deleted = table.Column<bool>(type: "bit", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Faqs", x => x.Id);
|
|
});
|
|
|
|
var viewName = "tv_FaqsWithNames";
|
|
var sql = @"CREATE FUNCTION tv_FaqsWithNames (@language nvarchar(2), @fallback nvarchar(2)) RETURNS TABLE AS RETURN
|
|
SELECT dbo.Faqs.*,
|
|
Isnull(JSON_VALUE(dbo.Faqs.QuestionLocalized, '$.' + @language), JSON_VALUE(dbo.Faqs.QuestionLocalized, '$.' + @fallback)) AS Question,
|
|
Isnull(JSON_VALUE(dbo.Faqs.AnswerLocalized, '$.' + @language), JSON_VALUE(dbo.Faqs.AnswerLocalized, '$.' + @fallback)) AS Answer
|
|
FROM dbo.Faqs";
|
|
|
|
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_FaqsWithNames";
|
|
migrationBuilder.Sql($"IF(exists (SELECT 1 FROM sys.objects WHERE Name = '{viewName}')) BEGIN DROP FUNCTION [dbo].[{viewName}] END {Environment.NewLine} GO");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Faqs");
|
|
}
|
|
}
|
|
}
|