![]() ![]() This will give you a head start in producing the migration script, although of course it won’t produce the file for you! I’ll demonstrate this approach using PostgreSQL as an example. As long you generate both build scripts using the same tool, and in the same way, you can then use a good Diff tool to compare the two and find out what has changed. We need a build script for the current branch, and one for the database as it existed at the point you created the branch. This means that we need to generate a build script on every migration, so we always have a saved record of the metadata for each version. However, if you have no database comparison tool for the RDBMS that you are using, the only obvious way to know which objects have changed and how, between two versions, is to compare build scripts. For example, build a second database, as it existed when you created your branch, apply the migration file, and then compare the resulting database to your current branch database. ![]() How? By making sure that the branch database built by the Flyway migration run is the same as the result of your glorious build spree. Finally, you need to check that it worked. Second, you need to produce a Flyway migration file to capture those changes. In this example, that’s the database version at point of branching. First, you need to find out which objects changed and how, by comparing your branch database – the result of your wild development efforts – to the current version that Flyway knows about. Capturing changes into a migration script You can then work through all the differences and write a script that does the necessary migration. I’ll demonstrate how to generate build scripts for each new version of a PostgreSQL database, and then compare them to get an overview of the differences between two versions. However, with many RDBMSs, you’re not going to have that luxury. If you have a schema comparison tool, such as SQL Compare, the task is easy as it can compare the two versions and generate a first-cut migration script for you. How you do that depends on the RDBMS that you are using, but there always a way. ![]() Your job now is to understand which objects changed, and then capture those changes, retrospectively, into a Flyway versioned migration. It will still report the database version as being unchanged from its original version, at the point of branching. Until your work is applied by Flyway, as a migration file that provides a version number to the migrated database, your development changes are outside of Flyway’s knowledge or control. It is all going so well until a little voice inside your head says, “ Hang on Buddy, this is supposed to go inside a migration”. Then you get rather carried away trying out lots of different ideas, running some tests and checks, using a visual tool to generate code for tables, and so on. You start off well enough, with a Flyway migration file that creates the development version of the database from zero (a blank database) to the point at which you branched. Imagine that you are a database developer, working on a new feature branch within the development branch of the database. He is a regular contributor to Simple Talk and SQLServerCentral. Phil Factor (real name withheld to protect the guilty), aka Database Mole, has 30 years of experience with database-intensive applications.ĭespite having once been shouted at by a furious Bill Gates at an exhibition in the early 1980s, he has remained resolutely anonymous throughout his career. ![]()
0 Comments
Leave a Reply. |