LANCommander/LANCommander.Server.Data.SQLite/Migrations/20231103052501_RemoveGameIconProperty.cs
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

56 lines
2 KiB
C#

using LANCommander.SDK.Enums;
using LANCommander.Server.Services;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LANCommander.Migrations
{
/// <inheritdoc />
public partial class RemoveGameIconProperty : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Migrate any old icons from the filesystem
if (Directory.Exists("Icon"))
foreach (var file in Directory.EnumerateFiles("Icon"))
{
var objectKey = Path.GetFileNameWithoutExtension(file);
var mediaId = Guid.NewGuid();
var fileId = Guid.NewGuid();
// Probably not an issue, but we'll check to make sure these are valid GUIDs just in case
if (Guid.TryParse(objectKey, out var gameId))
{
var sql = $@"
INSERT INTO Media
(Id, FileId, Type, SourceUrl, GameId, MimeType, CreatedOn, UpdatedOn)
SELECT
'{mediaId.ToString().ToUpper()}', '{fileId.ToString().ToUpper()}', '{(int)MediaType.Icon}', '', '{gameId.ToString().ToUpper()}', 'image/png', DateTime('now'), DateTime('now')
WHERE EXISTS (SELECT 1 FROM Games WHERE Id = '{gameId.ToString().ToUpper()}')
";
migrationBuilder.Sql(sql);
}
File.Move(file, Path.Combine("Media", fileId.ToString()));
}
migrationBuilder.DropColumn(
name: "Icon",
table: "Games");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Icon",
table: "Games",
type: "TEXT",
nullable: true);
}
}
}