2

I'd like to create schema automatically, if not exists. Currently I use this code to create schema:

new SchemaExport(_configuration)
           .SetDelimiter(";").SetOutputFile("schema.sql").Create(true, true);

But I have two problems with that:

1) It needs to have an empty schema to work. I'd like it to create an empty schema and user for itself, if I give it admin credentials for one time use.

2) I'd like it to create schema only if it is empty, or obsolete. Is it possible to make nhibernate check for that? Of course, in case of obsolete schema, I need a way to ask user whether to regenerate schema and loose data.

I'm using MySql 5, but I hope this is possible to achive without binding to concrete database provider.

Update: User needs to just install MySql and enter some admin credentials while installing it. After that he can run my application, and it should create it's own schema, user and assign rights, by asking admin credentials from user.

Archeg
  • 8,364
  • 7
  • 43
  • 90

1 Answers1

2

I answered a quite similar question here.

You have to check if the database is empty yourself and also create it if necessary. There is also a ValidateSchema method to check if the schema corresponds to the actual mapping definition. Everything else is your own code.

Users and rights may also be installed as DatabaseObjects in the mapping file.

Community
  • 1
  • 1
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193