Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…d=69) - Do not set recovery mode unless explicitly asked to.

Fix for issue 40 (chucknorris/roundhouse#40) - Make /debug switch work.
  • Loading branch information
ferventcoder committed Dec 20, 2011
1 parent 5579329 commit b829fae
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 13 deletions.
26 changes: 20 additions & 6 deletions product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Reflection;
using consoles;
using databases;
using folders;
using infrastructure;
using infrastructure.app;
Expand All @@ -14,6 +15,7 @@
using log4net;
using log4net.Core;
using log4net.Repository;
using log4net.Repository.Hierarchy;
using migrators;
using resolvers;
using runners;
Expand Down Expand Up @@ -61,14 +63,15 @@ public static ConfigurationPropertyHolder set_up_configuration_and_build_the_con
{
ConfigurationPropertyHolder configuration = new DefaultConfiguration();
parse_arguments_and_set_up_configuration(configuration, args);

ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration);
ApplicationConfiguraton.build_the_container(configuration);

if (configuration.Debug)
{
change_log_to_debug_level();
}

ApplicationConfiguraton.set_defaults_if_properties_are_not_set(configuration);
ApplicationConfiguraton.build_the_container(configuration);


return configuration;
}

Expand Down Expand Up @@ -254,10 +257,13 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
.Add("t|trx|transaction|wt|withtransaction",
"WithTransaction - This instructs RH to run inside of a transaction. Defaults to false.",
option => configuration.WithTransaction = option != null)
//simple
//recovery mode
.Add("simple",
"RecoveryModeSimple - This instructs RH to set the database recovery mode to simple recovery. Defaults to false.",
option => configuration.RecoveryModeSimple = option != null)
.Add("rcm=|recoverymode=",
"RecoveryMode - This instructs RH to set the database recovery mode to Simple|Full|NoChange. Defaults to NoChange.",
option => configuration.RecoveryMode = (RecoveryMode)Enum.Parse(typeof(RecoveryMode),option,true))
//debug
.Add("debug",
"Debug - This instructs RH to write out all messages. Defaults to false.",
Expand Down Expand Up @@ -319,7 +325,7 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
"/drop " +
"/d[onot]c[reatedatabase] " +
"/t[ransaction] " +
"/simple " +
"/r[e]c[overy]m[ode] NoChange|Simple|Full" +
"/debug " +
"/runallanytimescripts " +
"/disabletokenreplacement " +
Expand Down Expand Up @@ -355,6 +361,14 @@ public static void change_log_to_debug_level()
{
ILoggerRepository log_repository = LogManager.GetRepository(Assembly.GetCallingAssembly());
log_repository.Threshold = Level.Debug;
foreach (ILogger log in log_repository.GetCurrentLoggers())
{
var logger = log as log4net.Repository.Hierarchy.Logger;
if (logger != null)
{
logger.Level = log4net.Core.Level.Debug;
}
}
}

public static void run_migrator(ConfigurationPropertyHolder configuration)
Expand Down
2 changes: 1 addition & 1 deletion product/roundhouse.tasks/DBDeploy_MSBuild.proj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Silent="false"
DatabaseType="roundhouse.databases.sqlserver.SqlServerDatabase, roundhouse"
WithTransaction="false"
RecoveryModeSimple="false"
RecoveryMode="Full"
RunAllAnyTimeScripts="false"
DisableTokenReplacement="false"
/>
Expand Down
4 changes: 4 additions & 0 deletions product/roundhouse.tasks/Roundhouse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace roundhouse.tasks
{
using System;
using databases;
using folders;
using infrastructure.app;
using infrastructure.app.logging;
Expand Down Expand Up @@ -112,6 +113,9 @@ bool ITask.Execute()

public bool WithTransaction { get; set; }

public RecoveryMode RecoveryMode { get; set; }

[Obsolete("Use RecoverMode=Simple now")]
public bool RecoveryModeSimple { get; set; }

public bool Debug { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion product/roundhouse.tasks/samples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
Silent="false"
DatabaseType="roundhouse.databases.sqlserver.SqlServerDatabase, roundhouse"
WithTransaction="false"
RecoveryModeSimple="false"
RecoveryMode="Simple"
RunAllAnyTimeScripts="false"
DisableTokenReplacement="false"
/>
Expand Down
3 changes: 3 additions & 0 deletions product/roundhouse/RoundhousEFluentNHibernateDiffingType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace roundhouse
{
using System;

[Obsolete("Use RoundhouseMode",true)]
public enum RoundhousEFluentNHDiffingType
{
InitialDevelopment,
Expand Down
9 changes: 9 additions & 0 deletions product/roundhouse/RoundhouseMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace roundhouse
{
public enum RoundhouseMode
{
InitialDevelopment,
Maintenance,
MaintenanceWithRestore
}
}
6 changes: 5 additions & 1 deletion product/roundhouse/consoles/DefaultConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace roundhouse.consoles
{
using System;
using databases;
using infrastructure.app;
using infrastructure.logging;

Expand Down Expand Up @@ -33,7 +35,7 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public string ScriptsRunErrorsTableName { get; set; }
public string EnvironmentName { get; set; }
public bool Restore { get; set; }
public string RestoreFromPath { get; set; }
public string RestoreFromPath { get; set; }
public string RestoreCustomOptions { get; set; }
public int RestoreTimeout { get; set; }
public string CreateDatabaseCustomScript { get; set; }
Expand All @@ -44,6 +46,8 @@ public sealed class DefaultConfiguration : ConfigurationPropertyHolder
public bool Drop { get; set; }
public bool DoNotCreateDatabase { get; set; }
public bool WithTransaction { get; set; }
public RecoveryMode RecoveryMode { get; set; }
[Obsolete("Use RecoveryMode = Simple")]
public bool RecoveryModeSimple { get; set; }
public bool Debug { get; set; }
public bool DryRun { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions product/roundhouse/databases/RecoveryMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace roundhouse.databases
{
public enum RecoveryMode
{
NoChange,
Simple,
Full
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ public static void set_defaults_if_properties_are_not_set(ConfigurationPropertyH
{
configuration_property_holder.RestoreTimeout = ApplicationParameters.default_restore_timeout;
}

if (!string.IsNullOrEmpty(configuration_property_holder.RestoreFromPath))
{
configuration_property_holder.RestoreFromPath = Path.GetFullPath(configuration_property_holder.RestoreFromPath);
}
if (configuration_property_holder.RecoveryModeSimple)
{
configuration_property_holder.RecoveryMode = RecoveryMode.Simple;
}
}

private static void set_up_current_mappings(ConfigurationPropertyHolder configuration_property_holder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace roundhouse.infrastructure.app
{
using System;
using databases;

public interface ConfigurationPropertyHolder
{
Logger Logger { get; set; }
Expand Down Expand Up @@ -43,6 +46,8 @@ public interface ConfigurationPropertyHolder
bool Drop { get; set; }
bool DoNotCreateDatabase { get; set; }
bool WithTransaction { get; set; }
RecoveryMode RecoveryMode { get; set; }
[Obsolete("Use RecoveryMode = Simple")]
bool RecoveryModeSimple { get; set; }
bool Debug { get; set; }
bool DryRun { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions product/roundhouse/roundhouse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="connections\IConnection.cs" />
<Compile Include="consoles\CommandExecutor.cs" />
<Compile Include="consoles\InteractivePrompt.cs" />
<Compile Include="databases\RecoveryMode.cs" />
<Compile Include="infrastructure.app\ConnectionType.cs" />
<Compile Include="databases\DefaultDatabase.cs" />
<Compile Include="databases\MockDatabase.cs" />
Expand All @@ -134,6 +135,7 @@
<Compile Include="Migrate.cs" />
<Compile Include="resolvers\ScriptfileVersionResolver.cs" />
<Compile Include="RoundhousEFluentNHibernateDiffingType.cs" />
<Compile Include="RoundhouseMode.cs" />
<Compile Include="runners\RoundhouseNHibernateCompareRunner.cs" />
<Compile Include="runners\RoundhouseRedGateCompareRunner.cs" />
<Compile Include="sqlsplitters\StatementSplitter.cs" />
Expand Down
10 changes: 7 additions & 3 deletions product/roundhouse/runners/RoundhouseMigrationRunner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace roundhouse.runners
{
using System;
using databases;
using folders;
using infrastructure;
using infrastructure.app;
Expand Down Expand Up @@ -105,7 +106,11 @@ public void run()
{
database_migrator.open_admin_connection();
database_was_created = database_migrator.create_or_restore_database(get_custom_create_database_script());
database_migrator.set_recovery_mode(use_simple_recovery);
if (configuration.RecoveryMode != RecoveryMode.NoChange)
{
database_migrator.set_recovery_mode(configuration.RecoveryMode == RecoveryMode.Simple);
}

database_migrator.close_admin_connection();
}
database_migrator.open_connection(run_in_a_transaction);
Expand All @@ -119,8 +124,7 @@ public void run()
Log.bound_to(this).log_an_info_event_containing("{0}", "=".PadRight(50, '='));
string current_version = database_migrator.get_current_version(repository_path);
string new_version = version_resolver.resolve_version();
Log.bound_to(this).log_an_info_event_containing(" Migrating {0} from version {1} to {2}.", database_migrator.database.database_name,
current_version, new_version);
Log.bound_to(this).log_an_info_event_containing(" Migrating {0} from version {1} to {2}.", database_migrator.database.database_name,current_version, new_version);
long version_id = database_migrator.version_the_database(repository_path, new_version);

Log.bound_to(this).log_an_info_event_containing("{0}", "=".PadRight(50, '='));
Expand Down

0 comments on commit b829fae

Please sign in to comment.