Skip to content

Commit 220e3a4

Browse files
janpalascincuranet
authored andcommitted
Fixed invalid casting when generating downgrade migration to initial point (#67)
1 parent 03ad08a commit 220e3a4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Provider/src/EntityFramework.Firebird/FbMigrationSqlGenerator.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,19 @@ public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOp
5555
var updateDatabaseOperation = lastOperation as UpdateDatabaseOperation;
5656
var historyOperation = updateDatabaseOperation != null
5757
? updateDatabaseOperation.Migrations.First().Operations.OfType<HistoryOperation>().First()
58-
: (HistoryOperation)lastOperation;
59-
var modify = historyOperation.CommandTrees.First();
60-
_migrationsHistoryTableName = (modify.Target.Expression as DbScanExpression).Target.Table;
58+
: lastOperation as HistoryOperation;
59+
60+
if (historyOperation != null)
61+
{
62+
var modify = historyOperation.CommandTrees.First();
63+
_migrationsHistoryTableName = ((DbScanExpression)modify.Target.Expression).Target.Table;
64+
}
65+
//This happens only and only if downgrading database to initial point (ie. reverting also Initial migration)
66+
else
67+
{
68+
var dropTableOperation = (DropTableOperation)lastOperation; //DropTableOperation for MigrationHistory-table
69+
_migrationsHistoryTableName = Regex.Replace(dropTableOperation.Name, @".+\.(.+)", "$1");
70+
}
6171

6272
return GenerateStatements(migrationOperations).ToArray();
6373
}

0 commit comments

Comments
 (0)