1

I use Migrator Dot Net to version my database schema, and Fluent NHibernate to Map models to the schema.

Is there a good (read: automated) way to compare the schema generated by running migrations with the schema generated by the NH schema export to ensure that table definitions, keys, indices etc are in sync?

The only thing I can think of would be to export both schemas, then use some unknown (answer if you know a good one!) library to script them out, then compare script strings.

Is there a better way?

Edit: To Clarify, I would like to verify not only tables, columns, and column types, but also indices and foreign keys.

Brook
  • 5,949
  • 3
  • 31
  • 45

2 Answers2

4

There is a schema validator in NHibernate:

SchemaValidator validator = new SchemaValidator(configuration);
validator.Validate();
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • That looks perfect, does this validate indices and keys as well as the tables? – Brook Jul 08 '11 at 12:06
  • I actually don't know. I would expect that it validates everything that is also generated by `SchemaExport`, which are also keys, indives and constraints. To be sure, try it or read the code. – Stefan Steinegger Jul 08 '11 at 12:49
  • Looking at the code, It looks like it does check identity fields, but I don't think it is checking the keys or indices, that's a bummer. I wonder how hard it would be to add that, maybe I'll go that route. – Brook Jul 08 '11 at 13:26
3

I think that it would suffice to check that the mappings generated by FNH and your DB schema are in sync.
for that you can use this simple test

J. Ed
  • 6,692
  • 4
  • 39
  • 55
  • I think this still works, but it's slightly outdated. Stefan's and Sly's are more up to date. – Marijn Jul 08 '11 at 07:17