mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
namespace Marechai.Database.Migrations
|
|
{
|
|
public partial class AddMagazineIssueNumber : Migration
|
|
{
|
|
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)
|
|
{
|
|
// 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;
|
|
");
|
|
}
|
|
}
|
|
} |