Skip to content

Commit

Permalink
Merge pull request #291 from DbUp/revert-276-bug-tableExistsCheck271
Browse files Browse the repository at this point in the history
Revert "Removed exception handlers from the `DoesTableExist` method"
  • Loading branch information
droyad committed Nov 2, 2017
2 parents 4fdb1cf + 61378f5 commit 761b1df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/DbUp.Tests/Support/SQLite/SQLiteTableJournalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void creates_a_new_journal_table_when_not_exist()
var param2 = Substitute.For<IDbDataParameter>();
dbConnection.CreateCommand().Returns(command);
command.CreateParameter().Returns(param1, param2);
command.ExecuteScalar().Returns(x => 0L);
command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); });
var consoleUpgradeLog = new ConsoleUpgradeLog();
var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions");

Expand Down
6 changes: 1 addition & 5 deletions src/DbUp.Tests/TestInfrastructure/RecordingDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ public object ExecuteScalar()
{
add(DatabaseAction.ExecuteScalarCommand(CommandText));

if (CommandText == "error")
if (CommandText == "error" || (CommandText.ToLower().Contains("count") && CommandText.ToLower().Contains("schemaversion") && !schemaTableExists))
ThrowError();

if (CommandText.ToLower().Contains("count") && CommandText.ToLower().Contains("schemaversion") && !schemaTableExists)
return CommandText.Contains("sqlite") ? 0L : (object) null;

return null;
}

Expand Down
12 changes: 10 additions & 2 deletions src/DbUp/Support/Firebird/FirebirdTableJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ private bool DoesTableExist()
{
return connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
{
using (var command = dbCommandFactory())
try
{
using (var command = dbCommandFactory())
{
return VerifyTableExistsCommand(command);
}
}
// can't catch FbException here because this project does not depend upon Firebird
catch (DbException)
{
return VerifyTableExistsCommand(command);
return false;
}
});
}
Expand Down
11 changes: 9 additions & 2 deletions src/DbUp/Support/MySql/MySqlITableJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,16 @@ private bool DoesTableExist()
{
return connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
{
using (var command = dbCommandFactory())
try
{
using (var command = dbCommandFactory())
{
return VerifyTableExistsCommand(command, table, schema);
}
}
catch (DbException)
{
return VerifyTableExistsCommand(command, table, schema);
return false;
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions src/DbUp/Support/Postgresql/PostgresqlTableJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,17 @@ private bool DoesTableExist()
{
return connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
{
using (var command = dbCommandFactory())
try
{
using (var command = dbCommandFactory())
{
return VerifyTableExistsCommand(command, table, schema);
}
}
// can't catch NpgsqlException here because this project does not depend upon npgsql
catch (DbException)
{
return VerifyTableExistsCommand(command, table, schema);
return false;
}
});
}
Expand Down
15 changes: 13 additions & 2 deletions src/DbUp/Support/SqlServer/SqlTableJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,20 @@ private bool DoesTableExist()
{
return connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
{
using (var command = dbCommandFactory())
try
{
using (var command = dbCommandFactory())
{
return VerifyTableExistsCommand(command, table, schema);
}
}
catch (SqlException)
{
return false;
}
catch (DbException)
{
return VerifyTableExistsCommand(command, table, schema);
return false;
}
});
}
Expand Down

0 comments on commit 761b1df

Please sign in to comment.