Skip to content

Commit

Permalink
splitting the custom script - fixes issue 22 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Oct 23, 2011
1 parent 36c0887 commit 0c05805
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions product/roundhouse/databases/DefaultDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace roundhouse.databases
using NHibernate.Criterion;
using NHibernate.Tool.hbm2ddl;
using parameters;
using sqlsplitters;
using Environment = System.Environment;
using Version = model.Version;

Expand Down Expand Up @@ -98,10 +99,17 @@ public bool create_database_if_it_doesnt_exist(string custom_create_database_scr
}
}

var return_value = run_sql_scalar(create_script, ConnectionType.Admin);
if (return_value !=null)
if (split_batch_statements)
{
database_was_created = (bool) return_value;
foreach (var sql_statement in StatementSplitter.split_sql_on_regex_and_remove_empty_statements(create_script, sql_statement_separator_regex_pattern))
{
var return_value = run_sql_scalar(sql_statement, ConnectionType.Admin);
//should only receive a return value once
if (return_value != null)
{
database_was_created = (bool)return_value;
}
}
}
}
catch (Exception ex)
Expand Down
10 changes: 9 additions & 1 deletion product/roundhouse/migrators/DefaultDatabaseMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ public void close_connection()
public bool create_or_restore_database(string custom_create_database_script)
{
var database_created = false;
Log.bound_to(this).log_an_info_event_containing("Creating {0} database on {1} server if it doesn't exist.", database.database_name, database.server_name);

if (string.IsNullOrEmpty(custom_create_database_script))
{
Log.bound_to(this).log_an_info_event_containing("Creating {0} database on {1} server if it doesn't exist.", database.database_name, database.server_name);
}
else
{
Log.bound_to(this).log_an_info_event_containing("Creating {0} database on {1} server with custom script.", database.database_name, database.server_name);
}

database_created = database.create_database_if_it_doesnt_exist(custom_create_database_script);

Expand Down
3 changes: 2 additions & 1 deletion product/roundhouse/runners/RoundhouseMigrationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ private string get_custom_create_database_script()
return configuration.CreateDatabaseCustomScript;
}

if(file_system.file_exists(configuration.CreateDatabaseCustomScript))
//string custom_script_file = file_system.get_full_path(configuration.CreateDatabaseCustomScript);
if (file_system.file_exists(configuration.CreateDatabaseCustomScript))
{
return file_system.read_file_text(configuration.CreateDatabaseCustomScript);
}
Expand Down

0 comments on commit 0c05805

Please sign in to comment.