mycroforge/MycroForge.CLI/Commands/MycroForge.Db.Generate.Migration.cs
2024-07-23 22:04:51 +02:00

38 lines
1.2 KiB
C#

using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Db
{
public partial class Generate
{
public class Migration : Command, ISubCommandOf<Generate>
{
private static readonly Argument<string> NameArgument =
new(name: "name", description: "The name of the migration");
private readonly ProjectContext _context;
public Migration(ProjectContext context) : base("migration", "Generate a migration")
{
_context = context;
AddAlias("m");
AddArgument(NameArgument);
this.SetHandler(ExecuteAsync, NameArgument);
}
private async Task ExecuteAsync(string name)
{
await _context.Bash(
"source .venv/bin/activate",
$"alembic revision --autogenerate -m \"{name}\" --rev-id $(date -u +\"%Y%m%d%H%M%S\")"
);
}
}
}
}
}