SchemaUpdate to the rescue.
Well, day job is done for the day, and all of my work on Version 2 is done for the day as well. 3 posts in one day is a lot but it is easy to fill up a bunch quickly when they are all coming from months worth of things you've already done. Also, I know these blogs will start tapering off once I have caught up on everything, a point which is rapidly approaching.
Anyway, I wanted to post this one because I got a chance after work today to put one of my claims about my new framework to the test. As mentioned in my last post, Veronica has been using the software for a week today actually, so all of the main functionality is now in place and most of the screens and reports that will be in there a year from now are already in there. Last night she had mentioned a need to do something which required a new field to be added to the one of the main tables which would need to be used rather extensively, so both a DB change and changes in some of my existing applications.
This sort of change was exactly what made me drop Version 1, with the way the data was mapped and accessed and my lack of versioning it was simply too risky. I've talked a lot about how much better I felt about the stability and extensibility of the code in the new version, but this was really my first test of it.
First problem was the database itself. We are no longer dealing with a pre-production application. I have an existing database I now need to preserve and I needed to know how NHibernate could handle this. Would I need to modify the database manually and then the objects and mappings? Well it turns out that in the same namespace where I found ExportSchema, NHibernate also has a schema tool called UpdateSchema. So, if you have an NHibernate project this is definitely a valuable little tool to know about.
It will both update existing tables and create ones in the schema that don't yet exist. And while I couldn't find anything one way or another, it seems as though it leaves untouched tables that were already there but aren't in the current schema (better safe than sorry I guess). The tool worked exactly as anticipated. So, I added a new control value to my system table to hold the current database version and when you launch the application it will try and match it against the version number in assembly with my domain objects. If the values don't match the user is prompted to update the database and then it does it, otherwise, business as usual. Voila, the system now knows when and how to update itself! A feature that will definitely roll over into version 3 in one form or another.
Once the database and objects were updated, all I needed to do was update a few queries to pull the correct records based on the new field and a few of the forms needed to make changes to it. In the end both parts ended up being completely trivial. I spent more time testing than coding, I couldn't believe how quickly it was finished. Though my organizational skills are also improving I think which is also helping.
So now that Version 2 is up to speed, the next blog or two will likely be about Version 3 (which is really Version 1 of a completely different, currently unnamed project) and then updates on that and blogs about programming in general as they come up.
Anyway, I wanted to post this one because I got a chance after work today to put one of my claims about my new framework to the test. As mentioned in my last post, Veronica has been using the software for a week today actually, so all of the main functionality is now in place and most of the screens and reports that will be in there a year from now are already in there. Last night she had mentioned a need to do something which required a new field to be added to the one of the main tables which would need to be used rather extensively, so both a DB change and changes in some of my existing applications.
This sort of change was exactly what made me drop Version 1, with the way the data was mapped and accessed and my lack of versioning it was simply too risky. I've talked a lot about how much better I felt about the stability and extensibility of the code in the new version, but this was really my first test of it.
First problem was the database itself. We are no longer dealing with a pre-production application. I have an existing database I now need to preserve and I needed to know how NHibernate could handle this. Would I need to modify the database manually and then the objects and mappings? Well it turns out that in the same namespace where I found ExportSchema, NHibernate also has a schema tool called UpdateSchema. So, if you have an NHibernate project this is definitely a valuable little tool to know about.
It will both update existing tables and create ones in the schema that don't yet exist. And while I couldn't find anything one way or another, it seems as though it leaves untouched tables that were already there but aren't in the current schema (better safe than sorry I guess). The tool worked exactly as anticipated. So, I added a new control value to my system table to hold the current database version and when you launch the application it will try and match it against the version number in assembly with my domain objects. If the values don't match the user is prompted to update the database and then it does it, otherwise, business as usual. Voila, the system now knows when and how to update itself! A feature that will definitely roll over into version 3 in one form or another.
Once the database and objects were updated, all I needed to do was update a few queries to pull the correct records based on the new field and a few of the forms needed to make changes to it. In the end both parts ended up being completely trivial. I spent more time testing than coding, I couldn't believe how quickly it was finished. Though my organizational skills are also improving I think which is also helping.
So now that Version 2 is up to speed, the next blog or two will likely be about Version 3 (which is really Version 1 of a completely different, currently unnamed project) and then updates on that and blogs about programming in general as they come up.
Comments
Post a Comment