-
Notifications
You must be signed in to change notification settings - Fork 19
WhyUseMigrations
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:-
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.
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.
The DBMigrate plugin is setup to use CFWheels conventions for primary keys, foreign key references, automated timestamps and soft deletes.
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)
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.