testing whether a schema is created or is up-to-date

10 views
Skip to first unread message

Sean Farrow

unread,
May 20, 2013, 2:12:20 AM5/20/13
to nhu...@googlegroups.com

Hi,

 

I’m working on a project where I need to test whether a schema is up-to-date or has even been created.

I’m currently looking at the number of tables in the database and checking whether it is equal to the number of map files in the project.

Is there a more reliable way using NHibernate only?

Help appreciated.

Cheers

Sean.

Ricardo Peres

unread,
May 20, 2013, 9:23:28 AM5/20/13
to nhu...@googlegroups.com
Sure, an example using loquacious configuration:

Configuration cfg = this.CreateConfiguration()
.DataBaseIntegration(db =>
{
db.ConnectionStringName = "connectionStringName";
db.Dialect<MsSql2008Dialect>();
db.Driver<Sql2008ClientDriver>();
db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
db.SchemaAction = SchemaAutoAction.Validate;
})

The key is the SchemaAutoAction.Validate, it will check if any table is missing or does not have the required columns, in which case an exception will be thrown when the session factory is built. The other useful value is Update, which will create them.

RP

Sean Farrow

unread,
May 20, 2013, 10:07:49 AM5/20/13
to nhu...@googlegroups.com

Hi,

 

Thanks, just what I need.

Regards

Sean.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages