Reputation: 2195
I'm building a new app that is using NHibernate to generate the database schema but i can see a possible problem in the future.
Obviously you use all the data from your database is cleared when you update the schema but what stratagies do people use to restore any data to the new database. I am aware that massive changes to the schema will make this hard but was wondering how other people have dealt with this problem.
Cheers Colin G
PS I will not be doing this against the live database only using it to restore test data for integration test and continuous integration
Upvotes: 3
Views: 3525
Reputation: 854
Just a quick question directed @Chris Canal-
I understand that using a fluent interface to build your objects makes it look readable, but is it really worth the extra effort required to write these "builders" when you can use C# 3.0 syntax?
i.e. take your example:
var customer = new CustomerBuilder().WithFirstName("John").WithLastName("Doe").Build();
is this really worth the effort in constructing a "builder" when instead you can do this (which is arguably just as readable, and in fact less code)?:
var customer = new Customer { FirstName = "John", LastName = "Doe" };
Upvotes: 1
Reputation: 764
We do it similarly at our company. We use NHibernate to generate the database for our development and testing purposes. For testing we use SQLite as the back-end and just simply generate the test data separately for each test test suite.
When updating our staging/production servers we use SQLCompare and some manual editing if changes are more complex.
Upvotes: 0
Reputation: 4865
When testing, we use NHibernate to create the database, then a series of builders to create the data for each test fixture. We also use Sqlite for these tests, so they are lightening fast.
Our builders look a something like this:
public class CustomerBuilder : Builder<Customer>
{
string firstName;
string lastName;
Guid id = Guid.Empty;
public override Customer Build()
{
return new Customer() { Id = id, FirstName = firstName, LastName = }
}
public CustomerBuilder WithId(Guid newId)
{
id= newId;
return this;
}
public CustomerBuilder WithFirstName(string newFirstName)
{
firstName = newFirstName;
return this;
}
public CustomerBuilder WithLastName(string newLastName)
{
lastName = newLastName;
return this;
}
}
and usage:
var customer = new CustomerBuilder().WithFirstName("John").WithLastName("Doe").Build();
Because every line of code is written with TDD, we build up a comprehensive suite of data from scatch and will generally refactor some of it to factories that will wrap the above and make it a breeze to get dummy data in.
Upvotes: 5
Reputation: 862
I think it is a good thing in many situations to let NHibernate generate the schema for you. To recreate the test data you either use code driven by a testing framework (such as NUnit) or you could export your test data as a SQL script which you can run after you have updated the schema.
Upvotes: 1
Reputation: 2975
We don't update the schema from NHibernate. We use SQLCompare to move database schemas across environments. SQLCompare does this non-destructively.
If you're already using NHibernate I would recommend creating the test data with code.
Upvotes: 0