78 lines
3.6 KiB
C#
78 lines
3.6 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassi.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class CoinsViewsUpdate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
|
name: "LastUpdate",
|
|
table: "CoinsPerYears",
|
|
type: "datetimeoffset",
|
|
nullable: false,
|
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
|
|
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
|
name: "LastUpdate",
|
|
table: "CoinsPerMonths",
|
|
type: "datetimeoffset",
|
|
nullable: false,
|
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
|
|
|
var viewName = "vw_CoinsPerMonthWithNames";
|
|
var sql = @"SELECT CPM.*,
|
|
CONCAT(AU.FirstName, ' ' , AU.LastName) AS AppUserName, AU.Photo as AppUserPhoto
|
|
FROM CoinsPerMonths CPM
|
|
JOIN AppUsers AU ON AU.Id = CPM.AppUserId";
|
|
|
|
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");
|
|
|
|
viewName = "vw_CoinsPerYearWithNames";
|
|
sql = @"SELECT CPY.*,
|
|
CONCAT(AU.FirstName, ' ' , AU.LastName) AS AppUserName, AU.Photo as AppUserPhoto
|
|
FROM CoinsPerYears CPY
|
|
JOIN AppUsers AU ON AU.Id = CPY.AppUserId";
|
|
|
|
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");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropColumn(
|
|
name: "LastUpdate",
|
|
table: "CoinsPerYears");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "LastUpdate",
|
|
table: "CoinsPerMonths");
|
|
|
|
var viewName = "vw_CoinsPerMonthWithNames";
|
|
var sql = @"SELECT CPM.*,
|
|
CONCAT(AU.FirstName, ' ' , AU.LastName) AS AppUserName, AU.Photo as AppUserPhoto
|
|
FROM CoinsPerMonths CPM
|
|
JOIN AppUsers AU ON AU.Id = CPM.AppUserId";
|
|
|
|
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");
|
|
|
|
viewName = "vw_CoinsPerYearWithNames";
|
|
sql = @"SELECT CPY.*,
|
|
CONCAT(AU.FirstName, ' ' , AU.LastName) AS AppUserName, AU.Photo as AppUserPhoto
|
|
FROM CoinsPerYears CPY
|
|
JOIN AppUsers AU ON AU.Id = CPY.AppUserId";
|
|
|
|
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");
|
|
}
|
|
}
|
|
}
|