Hi all,

Allow me to preface this by saying I don't do much Open Source
development so please excuse me if this is not the correct place for
this discussion, or if I am reinventing the wheel.

As many of you know, NHibernate provides a simple API for Creating,
Updating, and Dropping a schema that it infers based on the set of
mappings in your domain model.  I think this is a great feature, but
one thing that bothered me is that I couldn't find a command line tool
that wrapped these mechanisms.  What I found my self doing was writing
simple unit tests and executing them via NUnit-Gui when I wanted to
update my schema.

I thought it would be nice to have a simple utility that would
integrate easily into CruiseControl.NET or other build tools.  I
couldn't find one online, so I built my own.  I am posting this here
with a simple description of how to use the tool so that other people
can let me know if it is worth sharing.  If so, I would like to open
source it and would certainly take any advice on offer for where the
best place to host the source code would be.

Current I am calling the tool "NHibernate Schema Tool" and you would
use it like this at the command line:

> nst /c:hibernate.cfg.xml /a:MyAssemblyWithEmbeddedMappingFiles.dll

The above command would use the specified hibernate configuration file
and add the specified assembly to it.  Then, by default it will
attempt to create the schema in the database.

If you store your domain objects in multiple assemblies along with
their embedded mapping files you can specify more than one argument to
the /a switch:

> nst /c:hibernate.cfg.xml /a:models1.dll;models2.dll;modelsN.dll

NST also supports other scenarios for where you store your mapping
files.  Let's say you store your mapping files in a directory and your
domain objects in an assembly.  You can still use NST to generate your
schema:

> nst /c:hibernate.cfg.xml /d:C:\Projects\Foo\MappingFiles 
> /m:AssemblyWithDomainClasses.dll

This will first load the AssemblyWithDomainClasses assembly into the
AppDomain and then add the mapping files in the given directory to the
NHibernate configuration.  It will then create the schema in the
database.

Another supported scenario is embedding your mapping files in an
assembly, but storing your domain classes in a separate assembly:

> nst /c:hibernate.cfg.xml /a:AssemblyWithMappingFiles.dll 
> /m:AssemblyWithDomainClasses.dll

Again, this will load the AssemblyWithDomainClasses assembly into the
AppDomain, and then will add the mappings embedded in the
AssemblyWithMappingFiles assembly to the NHibernate configuration.
The schema will then be created.

Now, you can also direct NST to actually perform an Update or Delete
of your schema as follows:

> nst /c:hibernate.cfg.xml /a:AssemblyWithMappingFilesAndClasses.dll /o:Update

or

> nst /c:hibernate.cfg.xml /a:AssemblyWithMappingFilesAndClasses.dll /o:Delete

or, if you are a very explicit person

> nst /c:hibernate.cfg.xml /a:AssemblyWithMappingFilesAndClasses.dll /o:Create

You can also get NST to output the script WITHOUT running it against
the database as follows:

> nst /s /c:hibernate.cfg.xml /a:AssemblyWithMappingFilesAndClasses.dll

Notice the /s switch.  This forces NST to operate in "silent" mode.
The script will be output to stdio, but will NOT be executed against
the database.  To both execute the script and output it to stdio you
would use the /v switch

> nst /v /c:hibernate.cfg.xml /a:AssemblyWithMappingFilesAndClasses.dll 
> /o:Update


Now, NST is itself just a thin command line wrapper around a simple
API.  I did this because that way people could use the API for
programmatic access, or maybe make a simple GUI if that was what they
wanted.

Anyway, if this tool sounds appealing please let me know and I will
work with the community here to figure out the best way to host the
source code.

Regards,

Dave Newman

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to