Skip to content

Roundhouserefreshdatabasefnh

ferventcoder edited this page Jun 19, 2011 · 30 revisions

RoundhousE + NHibernate == Rebuild Your Database without leaving Visual Studio!

Set up

  1. Create a console application
  2. Make it x86.
  3. Use NuGet to install roundhouse.refreshdatabase.fnh.
  4. Set the start up program to RefreshDatabase.Main().
  5. Add a project reference to your application's DLL that has the Fluent Mappings (and/or HBMs)
  6. OPTIONAL: Add a project reference to your application's DLL that has the conventions (could be the same as the step above).
  7. Set up the following code:
private static bool _isThisInitialDevelopment = true; //are you in greenfield or have you been to production?
private static string _nameOfInitialScript = "0001_CreateTables_NH.sql"; //name of the script that will be created by nhibernate SchemaExport
private static string _nameOfUpdateScript = "0002_AlterTables_NH.sql"; //name of the script that will be created by NH Schema Update. This one will change names the most over the lifetime of the project.
//roundhouse information
private static string _databaseName = "__REPLACE__"; //name of your database - installs to 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
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"; //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.

Running it

  1. Right click on the project and select Debug -> Start new instance.
  2. Watch it run. If any errors occur, you will be able to see them in the console or in the database it was working with under the ScriptsRunErrors table.
  3. If the errors occur with the schema generation, hopefully that hangs in the console long enough for you to decipher what is wrong.
Clone this wiki locally