Skip to content
Troy Murray edited this page Sep 15, 2011 · 1 revision

Why Use Migrations?

No matter how well you plan your database at the start of your project, there will nearly always be changes required during the course of development (things you didn't foresee, project specification changes etc.).

Migrations are an easy way to build and alter your database structure using cfscript.

Some of the reasons you may want to use migrations include:-

Version Control

As migrations are CFC files written in CFML and CFScript you can easily store them in your version control repository along with the rest of your application files. In fact, changes to the database structure can be committed to your repository along with the source code that requires those changes. Migrations also allow you to rollback your database structure should you need to rollback to a previous version of your application.

Multiple Developers

If you have more than one developer working on your project, each with their own development copy of the database, migrations make it easy to share additions and updates. Each time a developer gets the latest version of the application code, they can use the plugin tools to update their local database to the current version.

Conventions

The DBMigrate plugin is setup to use CFWheels conventions for primary keys, foreign key references, automated timestamps and soft deletes.

Database Independence

In theory, database migrations make it possible for you to easily switch between different databases. You could be developing your application using MySQL and deploy to a Microsoft SQL Server database on your production server using the migration files. (exceptions may be when you use database specific code in your migration files or your application code)

Deployment

Migrations make it easy to keep track of which changes need to be run against the production machines next time you deploy. You can temporarily set your application environment to maintenance, then run the migrations to update your production database. (Warning: backup your database first and ensure your migration files are not available to be downloaded) Also when you run your migrations the SQL code generated is also saved to text files. You may prefer to use these to update your production database.

Clone this wiki locally