60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace gehGassiApp.Data.Migrations
|
|
{
|
|
public partial class PublicWalkRequestDogsAdded : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "DogCount",
|
|
table: "PublicWalkRequests",
|
|
type: "INTEGER",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "DogsJson",
|
|
table: "PublicWalkRequests",
|
|
type: "TEXT",
|
|
nullable: true);
|
|
|
|
migrationBuilder.Sql("UPDATE PublicWalkRequests SET DogCount = 1");
|
|
migrationBuilder.Sql("UPDATE PublicWalkRequests SET DogsJson = '[{\"id\":\"' + PublicWalkRequests.DogId + '\",\"name\":\"Wuffi\"}]'");
|
|
|
|
var viewName = "vw_PublicWalkRequestWithNames";
|
|
var sql = @"SELECT PublicWalkRequests.*,
|
|
D.Name as DogName, D.Photo as DogPhoto
|
|
FROM PublicWalkRequests
|
|
LEFT JOIN Dogs D ON PublicWalkRequests.DogId = D.Id";
|
|
|
|
migrationBuilder.Sql($"DROP VIEW IF EXISTS {viewName};");
|
|
migrationBuilder.Sql($"CREATE VIEW {viewName} AS {sql}");
|
|
|
|
System.Diagnostics.Debug.WriteLine($"Migration PublicWalkRequestDogsAdded done");
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropColumn(
|
|
name: "DogCount",
|
|
table: "PublicWalkRequests");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "DogsJson",
|
|
table: "PublicWalkRequests");
|
|
|
|
var viewName = "vw_PublicWalkRequestWithNames";
|
|
var sql = @"SELECT PublicWalkRequests.*,
|
|
D.Name as DogName, D.Photo as DogPhoto
|
|
FROM PublicWalkRequests
|
|
LEFT JOIN Dogs D ON PublicWalkRequests.DogId = D.Id";
|
|
|
|
migrationBuilder.Sql($"DROP VIEW IF EXISTS {viewName};");
|
|
migrationBuilder.Sql($"CREATE VIEW {viewName} AS {sql}");
|
|
}
|
|
}
|
|
}
|