سؤال

We develop products for external, paying clients (i.e. we are not an internal IT function who only ever produce products for environments within our sphere of control) and we currently have to support both SQL Server 2005+ and Oracle 10.2+ as a back end. We use TeamCity with Wix for CI and builds which go to our testing team and, obviously, eventually to our clients when testing is signed off. Currently we have endless numbers of SQL scripts to upgrade databases. In the most basic form, there might be a DDL script and a data script (per version, per platform), but there can also be scripts containing stored procedures, and even client specific scripts. Depending upon how many versions a client is upgrading across (for instance 2.0 to 2.7) they may have to run as many as two dozen scripts, in the right order.

There's obviously a lot of scope for human error and there is currently no way of downgrading and thanks to a flaw in automatic version numbering of the scripts (and the rather shonky way the DB keeps a note of what scripts have been run), it's not always clear what has been run on a DB. Obviously this is not a great situation.

I'm investigating the use of Fluent Migrator, or similar - doesn't have to be Fluent - to try and bring a bit more order and version control to the whole process, but whilst there are plenty of articles and examples on how to use it with CI I can find nothing about integrating migrations into an MSI installer or similar.

What I want to do is either have it as part of our overall installer or produce one specifically for upgrading/downgrading databases. Leaving aside any client specific migrations for the moment, is it even possible to perform universal migrations from an installer like this? And if so, how about targeting multiple platforms in a single installer (i.e. having both SQL and Oracle migrations available and working out at runtime which to use)?

My plan would be to keep migrations in a single assembly (similar to the description in this article) and have the installer execute the appropriate up/down migration based on information baked in when the installer is created. Assuming it can be done, does this sound like a sensible solution or is there a better way of managing all this I'm not aware of?

Many thanks

Steve

هل كانت مفيدة؟

المحلول

Yes, it is absolutely possible.

To run FluentMigrator from your own code, you just have to create a RunnerContext and execute it. See the NAnt runner for a example (or the Console runner).

For targeting different platforms, you can control this when executing RunnerContext by passing in the database type through the Database parameter. Other options are passing in an ApplicationContext to be used within a migration. Or by using filtering with Tags that can be set on a migration.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top