Playlistr: commandbox-migrations

The CommandBox module commandbox-migrations will scaffold out your database with the tables and columns it needs for your application.

commandbox-migrations

Now we need to get a database onboard to store all our songs and playlists. We've chosen to use MySQL and have created a database called playlistr.

To allow commandbox-migrations to connect to our database we need to have a .env file that will hold all the connection details.

You won't find a .env file committed to this repository but you will find a example file, .env.example for you to rename and populate as shown.

Of course you'll need to change the DB_USER and DB_PASSWORD values to suit your configuration. With this in place we can get started with commandbox-migrations.

Remember: Don't allow that .env file be committed to your repository. You don't want those sensitive details recorded in your repository! Add a .env to your .gitignore file.

As you've made a change to the .env file you need to reload your CommandBox shell to pickup the changes.

.env

DB_CLASS=com.mysql.jdbc.Driver
DB_CONNECTIONSTRING=jdbc:mysql://localhost:3306/playlistr?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=true
DB_USER=playlistrDatabaseUsername
DB_PASSWORD=playlistrDatabasePassword

So what we need to do next is:

  • Reload the CommandBox shell
  • Initialise the commandbox-migrations setup
  • Install the cfmigrations table into your database
  • Add a migration script template

Advice: The migrate init will populate your box.json with configuration settings for cfmigrations. Many have found performance benefits in changing grammar setting, defaultGrammar, from AutoDiscover to that for your database engine. In our situation that would be MySQLGrammar.

commandbox

CommandBox:playlistr>reload
CommandBox:playlistr>migrate init
CommandBox:playlistr>migrate install
CommandBox:playlistr>migrate create artists