Permalink
Browse files

fix mysql migrations

  • Loading branch information...
1 parent 9eee1b1 commit 5907f52c7fab4ccd069400481201c96db773442e @soitgoes committed Jul 13, 2013
Showing with 14 additions and 13 deletions.
  1. +5 −2 Mite.Core/AnsiDatabaseRepository.cs
  2. +9 −11 Mite.MySql/MySqlDatabaseRepository.cs
@@ -122,7 +122,7 @@ public virtual MigrationTracker ExecuteUp(Migration migration)
var statements = split.Split(migration.UpSql);
foreach (var sql in statements)
{
- if (!string.IsNullOrEmpty(sql))
+ if (!string.IsNullOrWhiteSpace(sql))
{
var cmd = connection.CreateCommand();
cmd.Transaction = trans;
@@ -193,7 +193,10 @@ public virtual bool DatabaseExists()
bool result = false;
using (var conn = GetConnWithoutDatabaseSpecified())
{
- conn.Open();
+ if (conn.State != ConnectionState.Open)
+ {
+ conn.Open();
+ }
var cmd = conn.CreateCommand();
cmd.CommandText = "use " + DatabaseName;
try
@@ -10,8 +10,9 @@
namespace Mite.MySql
{
- public class MySqlDatabaseRepository : AnsiDatabaseRepository
- {
+ public class MySqlDatabaseRepository : AnsiDatabaseRepository
+ {
+ private string connectionString = "";
private string user;
private string password;
@@ -32,7 +33,8 @@ public MySqlDatabaseRepository (string connectionString, string filePath, string
}else
{
throw new Exception("Error parsing connection string using pattern: " + "(.*?)(UID|User Id)=(.*?);\\s*?(Password|Pwd)=(.*?)(;|$)");
- }
+ }
+ this.connectionString = connectionString;
this.connection = new MySqlConnection(connectionString);
}
@@ -56,14 +58,10 @@ public override MigrationTracker Init()
public override IDbConnection GetConnWithoutDatabaseSpecified()
{
- //return connection;
- var connString = connection.ConnectionString;
- var dbPattern = new Regex(@"Database=(.*?)(;|$)", RegexOptions.IgnoreCase);
- if (dbPattern.IsMatch(connString))
- {
- connString = dbPattern.Replace(connString, "");
- }
- return new MySqlConnection(connString);
+ var systemConnection = new MySqlConnection(connectionString);
+ systemConnection.Open();
+ systemConnection.ChangeDatabase("mysql");
+ return systemConnection;
}
public override void CreateDatabaseIfNotExists()

0 comments on commit 5907f52

Please sign in to comment.