Skip to content
Troy Murray edited this page Sep 15, 2011 · 2 revisions

Getting Started with DBMigrate

Installation

Download the latest version of DBMigrate-x.x.zip and place it in the plugins folder of your CFWheels application. Then reload your application.

Setting up your database

  1. First you need to create a database on a supported database server
  2. Then add a Coldfusion DSN using Coldfusion administrator
  3. Configure CFWheels to use your DSN using set(dataSourceName="") in config/settings.cfm see CFWheels Installation documentation for details. Currently DBMigrate only supports use of a single database for your application.

Creating Migrations

Now you're ready to begin adding migrations. Click on the DBMigrate link under Plugins in the CFWheels framework debugging footer. You can use the "Create new migration file from template" feature to get you started quickly or begin with a blank file.

Each migration is a CFC file with two functions, up to make changes to your database, and down to reverse those changes.

Migration files should be saved in a folder named /db/migrate/ and labeled sequentially with either a numeric or timestamp (yyyymmddhhmmss) prefix followed by a description of the migration. (e.g. a migration file that creates a users table could be named 001_users.cfc or 20100101123000_users.cfc)

For more information:

Running Migrations

Click on the DBMigrate link under Plugins in the CFWheels framework debugging footer. You should see that the current database version is 0 and the migrations you've created should be listed under the available migrations.

Use the select box to choose a version to migrate to and click the go button. This will migrate the database to that version and provide feedback on what was done.

The DBMigrate plugin will also save the SQL code that was executed in a folder named /db/sql/ for your reference.

You will also notice that the plugin created an extra table named schemainfo to store the current version number.

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.

Also when you run your migrations (e.g. in your design or development environment) the SQL code generated is also saved to text files. You may prefer to use these to update your production database, rather than run the DBMigrate plugin on the server.

Warning: Backup your database first! This plugin is designed to manipulate database structure (including dropping tables!). The plugin is provided "as is" without warranty of any kind.

(For security reasons you will also want to ensure your migration files are not available to be downloaded directly from your production server)

Clone this wiki locally