Skip to content

Commit 0bff066

Browse files
author
unknown
committed
Added support to call /task rollback:all and /task rollback:toversion /version X
1 parent 65dc1d4 commit 0bff066

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/FluentMigrator.Console/TaskExecutor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public void Execute(string task)
3333
_steps = 1;
3434
_migrationVersionRunner.Rollback(_steps);
3535
break;
36+
case "rollback:toversion":
37+
_migrationVersionRunner.RollbackToVersion( _version );
38+
break;
39+
case "rollback:all":
40+
_migrationVersionRunner.RollbackToVersion(0);
41+
break;
3642
case "migrate:down":
3743
_migrationVersionRunner.MigrateDown(_version);
3844
break;

src/FluentMigrator.Runner/MigrationVersionRunner.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface IMigrationVersionRunner
1717
void MigrateUp();
1818
void MigrateUp(long version);
1919
void Rollback(int steps);
20+
void RollbackToVersion( long version );
2021
void MigrateDown(long version);
2122
void RemoveVersionTable();
2223
}
@@ -171,8 +172,26 @@ public void Rollback(int steps)
171172
_versionInfo = null;
172173
}
173174

175+
public void RollbackToVersion(long version)
176+
{
177+
// Get the migrations between current and the to version
178+
foreach (var migrationNumber in VersionInfo.AppliedMigrations())
179+
{
180+
if (version < migrationNumber || version == 0)
181+
{
182+
migrateDown(migrationNumber);
183+
}
184+
}
185+
186+
if (version == 0)
187+
RemoveVersionTable();
188+
189+
_versionInfo = null;
190+
}
191+
174192
public void MigrateDown(long version)
175193
{
194+
176195
migrateDown(version);
177196
_versionInfo = null;
178197
}

0 commit comments

Comments
 (0)