Skip to content

Commit

Permalink
Merge pull request #83 from Ujinjinjin/fix/down-command-issues
Browse files Browse the repository at this point in the history
#80, #81 fix issues with down command
  • Loading branch information
Ujinjinjin authored Aug 19, 2024
2 parents 0681168 + a1c771c commit ec21c94
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Src/Dingo.Cli/Controllers/MigrationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ private Command GetDownCommand()
"Root path to database migration files",
true
);
var countOption = OptionFactory.CreateOption<int>(
var countOption = OptionFactory.CreateOption<int?>(
new[] { "--count" },
"Number of patches to rollback. Default: 1",
false
);
var forceOption = OptionFactory.CreateOption<bool>(
new[] { "--force", "-f" },
"Ignore all warnings and rollback patches",
true
false
);

var command = CommandFactory.CreateCommand(
Expand Down
2 changes: 1 addition & 1 deletion Src/Dingo.Core/Services/Handlers/IMigrationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface IMigrationHandler
Task MigrateAsync(string? profile, string path, CancellationToken ct = default);

/// <summary> Rollback last N patches </summary>
Task RollbackAsync(string? profile, string path, int patchCount, bool force, CancellationToken ct = default);
Task RollbackAsync(string? profile, string path, int? patchCount, bool force, CancellationToken ct = default);
}
6 changes: 4 additions & 2 deletions Src/Dingo.Core/Services/Handlers/MigrationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Dingo.Core.Services.Handlers;

internal class MigrationHandler : IMigrationHandler
{
private const int DefaultPatchRollbackCount = 1;

private readonly IMigrationGenerator _migrationGenerator;
private readonly IMigrationComparer _migrationComparer;
private readonly IMigrationScanner _migrationScanner;
Expand Down Expand Up @@ -75,7 +77,7 @@ public async Task MigrateAsync(string? profile, string path, CancellationToken c
public async Task RollbackAsync(
string? profile,
string path,
int patchCount,
int? patchCount,
bool force,
CancellationToken ct = default
)
Expand All @@ -85,7 +87,7 @@ public async Task RollbackAsync(
try
{
await _profileLoader.LoadAsync(profile, ct);
await _migrationRunner.RollbackAsync(path, patchCount, force, ct);
await _migrationRunner.RollbackAsync(path, patchCount ?? DefaultPatchRollbackCount, force, ct);
}
catch (Exception ex)
{
Expand Down

0 comments on commit ec21c94

Please sign in to comment.