Skip to content

Commit

Permalink
Fixed a nasty bug with SQL Server where it tries to hold a connection…
Browse files Browse the repository at this point in the history
… (interferes with drop/create mode) and gives a transport error. Custom Scripts also run token replacement. Two new switches available, CommandTimeout and CommandTimeoutAdmin. Migrate doesn't try to configure log4net now (causes issues w/libraries that do). Two new folders available: Indexes and AlterDatabase. Fix for Included sample for Oracle doesn't work. See [issue 55] (http://code.google.com/p/roundhouse/issues/detail?id=55) for details.
  • Loading branch information
ferventcoder committed Jul 1, 2011
1 parent 3e5898f commit a1d064a
Show file tree
Hide file tree
Showing 51 changed files with 486 additions and 192 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ _ReSharper*
*.cache
*~
*.swp
*.bak
*.orig
*.log

Expand Down
29 changes: 18 additions & 11 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
Project RoundhousE - Database Change Management done right
=======
![RoundhousE](http://github.com/ferventcoder/roundhouse/raw/master/docs/logo/RoundhousE_Logo.jpg "RoundhousE - Professional Database Management.")

<img src="http://github.com/ferventcoder/roundhouse/raw/master/docs/logo/RoundhousE_Logo.jpg" height="200" alt="RoundhousE - Professional Database Management" />
# LICENSE
Apache 2.0 - see docs\legal (just LEGAL in the zip folder)

Apache 2.0 - see docs\legal (just LEGAL in the zip folder)

# Documentation
[WIKI](https://github.com/chucknorris/roundhouse/wiki)

# IMPORTANT
NOTE: If you are looking at the source - please run build.bat before opening the solution. It creates the SolutionVersion.cs file that is necessary for a successful build.

# INFO
## Overview
RoundhousE is an automated database deployment (change management) system that allows you to use your current idioms and gain much more. Currently it only supports Microsoft SQL Server, but there are future plans for other databases.

It seeks to solve both maintenance concerns and ease of deployment. We follow some of the same idioms as other database management systems (SQL scripts), but we are different in that we think about future maintenance concerns. We want to always apply certain scripts (anything stateless like functions, views, stored procedures, and permissions), so we don't have to throw everything into our change scripts. This seeks to solves future source control concerns. How sweet is it when you can version the database according to your current source control version?

##[WIKI](https://github.com/chucknorris/roundhouse/wiki)

RoundhousE is an automated database deployment (change management) system that allows you to use your current idioms and gain much more. Currently it only supports Microsoft SQL Server, but there are future plans for other databases.

It seeks to solve both maintenance concerns and ease of deployment. We follow some of the same idioms as other database management systems (SQL scripts), but we are different in that we think about future maintenance concerns. We want to always apply certain scripts (anything stateless like functions, views, stored procedures, and permissions), so we don't have to throw everything into our change scripts. This seeks to solves future source control concerns. How sweet is it when you can version the database according to your current source control version?

## Getting started with RoundhousE
### Downloads
You can download RoundhousE from [http://code.google.com/p/roundhouse/downloads/list](http://code.google.com/p/roundhouse/downloads/list)
Expand Down Expand Up @@ -62,13 +63,19 @@ It helps keep to the product updated, pays for site hosting, etc. https://www.pa

# RELEASE NOTES
=0.8.0.x=
* FIX: Fixed a nasty bug with SQL Server where it tries to hold a connection (interferes with drop/create mode) and gives a transport error (r331)
* Custom Scripts also run token replacement (r321, r330)
* Two new switches available, CommandTimeout and CommandTimeoutAdmin! (r329)
* FIX: Migrate doesn't try to configure log4net now (causes issues w/libraries that do) (r326)
* Two new folders available: Indexes and AlterDatabase (r324)
* FIX: Included sample for Oracle doesn't work. See [issue 55] (http://code.google.com/p/roundhouse/issues/detail?id=55) for details. (r322)
* RH now works with MySQL. Thanks Diyan. See details https://github.com/chucknorris/roundhouse/pull/3 (r317)

=0.8.0.300=
* RH now does token replacement in the sql files using '{{PropertyName}}'. See [issue 33] (http://code.google.com/p/roundhouse/issues/detail?id=33) for details. (r299)
* Always run files that have '.EVERYTIME.' in the name. See [issue 51] (http://code.google.com/p/roundhouse/issues/detail?id=51) for details. (r299)
* RoundhousE ships a DLL for embedding. See [issue 44] (http://code.google.com/p/roundhouse/issues/detail?id=44) for details. It has a semi-fluent interface - see (https://gist.github.com/977990) for details. (r299)
* FIXED: Environment Specific Files run other environments when other environments are part of the name (i.e. BOBTEST is run with TEST). See [issue 50] (http://code.google.com/p/roundhouse/issues/detail?id=50) for details. (r299)
* FIX: Environment Specific Files run other environments when other environments are part of the name (i.e. BOBTEST is run with TEST). See [issue 50] (http://code.google.com/p/roundhouse/issues/detail?id=50) for details. (r299)
* A folder that runs after the other anytime scripts folders have run has been added. See https://github.com/chucknorris/roundhouse/pull/1 for details. (r297)
* Fixing the script modified twice running each time bug. See https://github.com/chucknorris/roundhouse/pull/5 for details. (r296)
* Sample is now a project in the release folder. (r287)
Expand Down
3 changes: 2 additions & 1 deletion db/Oracle/TestRoundhousE/functions/ufn_GetDate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ IS
BEGIN
SELECT SYSDATE INTO v_Today FROM dual;
RETURN v_Today;
END;
END
;
3 changes: 2 additions & 1 deletion db/Oracle/TestRoundhousE/sprocs/usp_GetDate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ CREATE OR REPLACE PROCEDURE usp_GetDate
AS
BEGIN
SELECT ufn_GetDate('0') INTO v_date FROM dual;
END;
END
;
3 changes: 2 additions & 1 deletion db/Oracle/TestRoundhousE/sprocs/usp_SelectTimmy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ CREATE OR REPLACE PROCEDURE usp_SelectTimmy
AS
BEGIN
SELECT ID INTO v_ID FROM vw_Dude;
END;
END
;
8 changes: 4 additions & 4 deletions db/Oracle/TestRoundhousE/up/0001_CreateTables.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

CREATE TABLE Timmy
(
ID Number(19,0) NOT NULL
,dude varchar(50) NULL
);

ALTER TABLE Timmy ADD (PRIMARY KEY(id));
)
;
ALTER TABLE Timmy ADD (PRIMARY KEY(id))
;
3 changes: 2 additions & 1 deletion db/Oracle/TestRoundhousE/up/0002_ChangeTable.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ALTER TABLE Timmy DROP COLUMN dude;
ALTER TABLE Timmy DROP COLUMN dude
;
17 changes: 3 additions & 14 deletions db/Oracle/TestRoundhousE/up/0003_TestBatchSplitter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
USE database name
;
*/
SELECT SYSDATE FROM dual;
SELECT SYSDATE FROM dual
;
SELECT SYSDATE FROM dual
;
SELECT SYSDATE FROM dual
;
SELECT SYSDATE FROM dual;
SELECT SYSDATE FROM dual;
SELECT SYSDATE FROM dual;

--;
-- ;
Expand All @@ -20,14 +12,11 @@ SELECT SYSDATE FROM dual;
G
O
*/
/* ;
*/
/*
;
*/
-- ='.>?<)-* ;
-- ='.>?<)-*
-- BOB) ;
/*
; */
/* ;
alsdkjaslkkjf */
alsdkjaslkkjf */
SELECT SYSDATE FROM dual
3 changes: 2 additions & 1 deletion db/Oracle/TestRoundhousE/views/vw_Dude.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE OR REPLACE VIEW vw_Dude AS
SELECT ID FROM Timmy;
SELECT ID FROM Timmy
;
46 changes: 24 additions & 22 deletions nuget/roundhouse.refreshdatabase.fnh/content/RefreshDatabase.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
using System.Reflection;
using roundhouse;

public class RefreshDatabase
public partial class RefreshDatabase
{
//https://github.com/chucknorris/roundhouse/wiki/Roundhouserefreshdatabasefnh
//Note: This should be added to a console application that is set to x86.

private static bool _isThisInitialDevelopment = true;
private static string _nameOfInitialScript = "0001_CreateTables_NH.sql";
private static string _nameOfUpdateScript = "0002_AlterTables_NH.sql";
private static bool _isThisInitialDevelopment = true; //are you in greenfield or have you been to production?
private static string _nameOfScript = "0001_CreateTables_NH.sql"; //name of the script that will be created by nhibernate SchemaExport/SchemaUpdate - this will change the most over time as you move into maintenance

private static string _databaseName = "__REPLACE__";
private static string _pathToSqlScripts = @"..\..\..\__REPLACE__";
private static string _repositoryPath = "__REPLACE__";

private static bool _restoreDuringMaintenance = true;
private static string _pathToRestore = @"\\__REPLACE__.bak";
private static string _databaseName = "__REPLACE__"; //name of your database on your local default instance
private static string _pathToSqlScripts = @"..\..\..\__REPLACE__"; //This is the path to your scripts folder where Up/Views/Functions/Sprocs are the next folder below. This is a relative path from bin\Debug. The three sets of parent folders already here should get it out of your project folder so you can traverse into the database project folder.
private static string _repositoryPath = "__REPLACE__"; //The path to your source control repository. Used only for information sake.

//restore
private static bool _restoreDuringMaintenance = true; //you want to restore if you have a production backup that is small enough. Otherwise you get into a bit more advanced scenario that this package doesn't cover well
private static string _pathToRestore = @"\\__REPLACE__.bak"; //this is the path to the restore file, likely on the network so everyone can get to it

//Note: Add a reference to the project that has the Mappings/Conventions
private static string _mappingsAssemblyPath = @".\__REPLACE__.dll";
private static string _conventionsAssemblyPath = @".\__REPLACE__.dll";
private static string _mappingsAssemblyPath = @".\__REPLACE__.dll"; //After adding a reference, the file will be in the build directory, so you can just add the name of the dll here.
private static string _conventionsAssemblyPath = @".\__REPLACE__.dll"; //If you don't have a conventions assembly, just use the same DLL you just used for mappings.

private static void Main(string[] args)
{
Expand All @@ -58,21 +59,22 @@
var mappingsAssembly = Assembly.LoadFrom(_mappingsAssemblyPath);
var conventionsAssembly = Assembly.LoadFrom(_conventionsAssemblyPath);

var migrator = new Migrate().Set(c => {
c.DatabaseName = _databaseName;
c.RepositoryPath = _repositoryPath;
c.SqlFilesDirectory = _pathToSqlScripts;
c.RestoreFromPath = _pathToRestore;
c.Silent = true;
c.RecoveryModeSimple = true;
});
var migrator = new Migrate().Set(c =>
{
c.Logger = new roundhouse.infrastructure.logging.custom.ConsoleLogger();
c.DatabaseName = _databaseName;
c.RepositoryPath = _repositoryPath;
c.SqlFilesDirectory = _pathToSqlScripts;
c.RestoreFromPath = _pathToRestore;
c.Silent = true;
c.RecoveryModeSimple = true;
});


var diffType = _restoreDuringMaintenance ? RoundhousEFluentNHDiffingType.MaintenanceWithRestore : RoundhousEFluentNHDiffingType.Maintenance;
var scriptName = _nameOfUpdateScript;
var scriptName = _nameOfScript;
if (_isThisInitialDevelopment)
{
scriptName = _nameOfInitialScript;
diffType = RoundhousEFluentNHDiffingType.InitialDevelopment;
}

Expand Down
23 changes: 20 additions & 3 deletions product/roundhouse.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void report_version()
public static ConfigurationPropertyHolder set_up_configuration_and_build_the_container(string[] args)
{

ConfigurationPropertyHolder configuration = new ConsoleConfiguration();
ConfigurationPropertyHolder configuration = new DefaultConfiguration();
parse_arguments_and_set_up_configuration(configuration, args);
if (configuration.Debug)
{
Expand Down Expand Up @@ -103,6 +103,14 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
.Add("csa=|connstringadmin=|connectionstringadministration=",
string.Format("ConnectionStringAdministration - This is used for connecting to master when you may have a different uid and password than normal."),
option => configuration.ConnectionStringAdmin = option)
.Add("ct=|commandtimeout=",
string.Format("CommandTimeout - This is the timeout when commands are run. This is not for admin commands or restore. Defaults to \"{0}\".",
ApplicationParameters.default_command_timeout),
option => configuration.CommandTimeout = int.Parse(option))
.Add("cta=|commandtimeoutadmin=",
string.Format("CommandTimeoutAdministration - This is the timeout when administration commands are run (except for restore, which has its own). Defaults to \"{0}\".",
ApplicationParameters.default_admin_command_timeout),
option => configuration.CommandTimeoutAdmin = int.Parse(option))
//database type
.Add("dt=|dbt=|databasetype=",
string.Format("DatabaseType - Tells RH what type of database it is running on. This is a plugin model. This is the fully qualified name of a class that implements the interface roundhouse.sql.Database, roundhouse. If you have your own assembly, just set it next to rh.exe and set this value appropriately. Defaults to 'sqlserver' which is a synonym for '{0}'.",
Expand All @@ -121,6 +129,10 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
ApplicationParameters.default_version_x_path),
option => configuration.VersionXPath = option)
// folders
.Add("ad=|alterdatabase=|alterdatabasefolder=|alterdatabasefoldername=",
string.Format("AlterDatabaseFolderName - The name of the folder where you keep your alter database scripts. Read up on token replacement. You will want to use {{DatabaseName}} here instead of specifying a database name. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_alter_database_folder_name),
option => configuration.AlterDatabaseFolderName = option)
.Add("u=|up=|upfolder=|upfoldername=",
string.Format("UpFolderName - The name of the folder where you keep your update scripts. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_up_folder_name),
Expand All @@ -145,6 +157,10 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
string.Format("SprocsFolderName - The name of the folder where you keep your stored procedures. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_sprocs_folder_name),
option => configuration.SprocsFolderName = option)
.Add("ix=|indexes=|indexesfolder=|indexesfoldername=",
string.Format("IndexesFolderName - The name of the folder where you keep your indexes. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_indexes_folder_name),
option => configuration.IndexesFolderName = option)
.Add("ra=|runAfterOtherAnyTimeScripts=|runAfterOtherAnyTimeScriptsfolder=|runAfterOtherAnyTimeScriptsfoldername=",
string.Format("RunAfterOtherAnyTimeScriptsFolderName - The name of the folder where you keep scripts that will be run after all of the other any time scripts complete. Will recurse through subfolders. Defaults to \"{0}\".",
ApplicationParameters.default_runAfterOtherAnyTime_folder_name),
Expand Down Expand Up @@ -257,10 +273,11 @@ private static void parse_arguments_and_set_up_configuration(ConfigurationProper
"/[sql]f[ilesdirectory] VALUE " +
"/s[ervername] VALUE " +
"/c[onnection]s[tring]a[dministration] VALUE " +
"/c[ommand]t[imeout] VALUE /c[ommand]t[imeout]a[dmin] VALUE " +
"/r[epositorypath] VALUE /v[ersion]f[ile] VALUE /v[ersion]x[path] VALUE " +
"/u[pfoldername] VALUE /do[wnfoldername] VALUE " +
"/a[lter]d[atabasefoldername] VALUE /u[pfoldername] VALUE /do[wnfoldername] VALUE " +
"/r[un]f[irstafterupdatefoldername] VALUE /fu[nctionsfoldername] VALUE /v[ie]w[sfoldername] VALUE " +
"/sp[rocsfoldername] VALUE /p[ermissionsfoldername] VALUE " +
"/sp[rocsfoldername] VALUE /i[nde]x[foldername] VALUE /p[ermissionsfoldername] VALUE " +
"/sc[hemaname] VALUE /v[ersion]t[ablename] VALUE /s[cripts]r[un]t[ablename] VALUE /s[cripts]r[un]e[rrors]t[ablename] VALUE " +
"/env[ironmentname] VALUE " +
"/restore /r[estore]f[rom]p[ath] VALUE /r[estore]c[ustom]o[ptions] VALUE /r[estore]t[imeout] VALUE" +
Expand Down
8 changes: 6 additions & 2 deletions product/roundhouse.databases.access/AccessDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using roundhouse.infrastructure.logging;

namespace roundhouse.databases.access
{
using System;
Expand Down Expand Up @@ -65,13 +67,14 @@ public override void initialize_connections(ConfigurationPropertyHolder configur

set_provider();
admin_connection_string = connection_string;
configuration_property_holder.ConnectionStringAdmin = admin_connection_string;
//set_repository(configuration_property_holder);
}

public override void open_admin_connection()
{
server_connection = new AdoNetConnection(new OleDbConnection(admin_connection_string));
server_connection.open();
admin_connection = new AdoNetConnection(new OleDbConnection(admin_connection_string));
admin_connection.open();
}

public override void open_connection(bool with_transaction)
Expand Down Expand Up @@ -100,6 +103,7 @@ private static string build_connection_string(string server_name, string databas

public override void run_database_specific_tasks()
{
Log.bound_to(this).log_a_debug_event_containing("Access has no specific database tasks. Returning...");
//TODO: Anything for Access?
}

Expand Down
13 changes: 10 additions & 3 deletions product/roundhouse.databases.mysql/MySqlDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace roundhouse.databases.mysql
using roundhouse.infrastructure.logging;

namespace roundhouse.databases.mysql
{
using System;
using infrastructure.app;
Expand Down Expand Up @@ -54,6 +56,7 @@ public override void initialize_connections(ConfigurationPropertyHolder configur
builder.Database = "information_schema";
admin_connection_string = builder.ConnectionString;
}
configuration_property_holder.ConnectionStringAdmin = admin_connection_string;
}

public override void set_provider()
Expand All @@ -78,16 +81,20 @@ public override string delete_database_script()

public override void run_database_specific_tasks()
{
//nothing to see here. move along now.
Log.bound_to(this).log_a_debug_event_containing("MySQL has no database specific tasks. Moving along now...");
}

// http://bugs.mysql.com/bug.php?id=46429
public override void run_sql(string sql_to_run)
public override void run_sql(string sql_to_run,ConnectionType connection_type)
{
if (string.IsNullOrEmpty(sql_to_run)) return;

//TODO Investigate how pass CommandTimeout into commands which will be during MySqlScript execution.
var connection = server_connection.underlying_type().downcast_to<MySqlConnection>();
if (connection_type == ConnectionType.Admin)
{
connection = admin_connection.underlying_type().downcast_to<MySqlConnection>();
}
var script = new MySqlScript(connection, sql_to_run);
script.Execute();
}
Expand Down
Loading

0 comments on commit a1d064a

Please sign in to comment.