39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.CommandLine;
|
|
using MycroForge.CLI.Commands.Interfaces;
|
|
|
|
namespace MycroForge.CLI.Commands;
|
|
|
|
public partial class MycroForge
|
|
{
|
|
public partial class Orm
|
|
{
|
|
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)
|
|
{
|
|
_context.AssertDirectoryExists("orm/versions");
|
|
|
|
await _context.Bash(
|
|
"source .venv/bin/activate",
|
|
$"alembic revision --autogenerate -m \"{name}\" --rev-id $(date -u +\"%Y%m%d%H%M%S\")"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |