BP3's extensions to FluentMigrator.
BP3 recommends all database development to be done using migrations (see Evolutionary Database Design by Martin Fowler). The specific choice of migration tooling will depend upon the technology stack being used, but for Microsoft stacks then FluentMigrator is recommended.
FluentMigrator does a great job with the database schema but doesn't handle Stored Procedures quite so well. It is in the nature of the sort of DB development that BP3 engages in that Stored Procedures are potentially more important than they would be for other Developers. Thus, the classes that you will find here extend the FluentMigrator base Migration class to provide better support for working with Stored Procedures.
- Add the classes found here to your FluentMigrator project
- Have your migration classes extend the
BP3Migrationclass (from theBP3Migrations.Migrationspackage) rather than theMigrationclass (from theFluentMigratorpackage) - Make sure to call the
BP3Migrationconstructor with the name of the project folder - For each Stored Procedure file instantiate a
ProcedureFileand add it to aList<ProcedureFile>- don't forget to specify version and revision as required - Call the
CreateStoredProceduremethod of theSPHelpermember variable with the list of ProcedureFiles in theUpmethod - Call the
DropStoredProceduremethod of theSPHelpermember variable with the list of ProcedureFiles in theDownmethod
The assumptions underpinning this implementation are
- Stored Procedures should have a version, e.g. v1, v2, etc
- A new version should be created each time the interface to the Stored Procedure changes
- The old version is not removed when a new version is created so as to suppport old code
- Stored Procedures can have revisions, e.g. '000', '001', etc
- For every Stored Procedure version the latest revision should be the current one
- When you create a new version of a Stored Procedure go back and create a new revision of the previous version that calls the new version you just created