mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
fix: Make migration for IssueNumber column idempotent in MagazineIssues table
This commit is contained in:
@@ -1,13 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Marechai.Database.Migrations
|
||||
{
|
||||
public partial class AddMagazineIssueNumber : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder) =>
|
||||
migrationBuilder.AddColumn<uint>("IssueNumber", "MagazineIssues", nullable: true);
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Check if the column already exists before adding it (idempotent)
|
||||
migrationBuilder.Sql(@"
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'MagazineIssues'
|
||||
AND COLUMN_NAME = 'IssueNumber'
|
||||
)
|
||||
THEN
|
||||
ALTER TABLE `MagazineIssues` ADD `IssueNumber` int unsigned NULL;
|
||||
END IF;
|
||||
");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder) =>
|
||||
migrationBuilder.DropColumn("IssueNumber", "MagazineIssues");
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Check if the column exists before dropping it (idempotent)
|
||||
migrationBuilder.Sql(@"
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'MagazineIssues'
|
||||
AND COLUMN_NAME = 'IssueNumber'
|
||||
)
|
||||
THEN
|
||||
ALTER TABLE `MagazineIssues` DROP COLUMN `IssueNumber`;
|
||||
END IF;
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user