Setup

Let's start with CommandBox

CommandBox

The best way to get started with a ColdBox application is to fire up CommandBox.

	>box

	______                                          ______
	/ ____/___  ____ ___  ____ ___  ____ _____  ____/ / __ )____  _  __
	/ /   / __ \/ __ `__ \/ __ `__ \/ __ `/ __ \/ __  / __  / __ \| |/_/
	/ /___/ /_/ / / / / / / / / / / / /_/ / / / / /_/ / /_/ / /_/ />  <
	\____/\____/_/ /_/ /_/_/ /_/ /_/\__,_/_/ /_/\__,_/_____/\____/_/|_| (R)  v4.0.0+01015

	Computers are good at following instructions, but not at reading your mind.

	Welcome to CommandBox!
	CommandBox:webroot>server start
	CommandBox:webroot>install coldbox
	CommandBox:webroot>coldbox create app playlistr
				

Next we need to install commandbox-migrations to help us build our sample database schema.

CommandBox Migrations

	CommandBox:webroot>install cfmigrations
	CommandBox:webroot>migrate init
				

Now we need a database. Create a database in the engine of your choice and that is supported by Quick. This project assumes the database is called playlistr.

If you look inside the box.json file which migrate init has updated, there are a number of environment variable placeholders such as ${DB_USER}. This allows you to place these senstive values into environment variable on your server platform. You can also populate a .env file in your webroot which commandbox-migrations will use in the absence of server environment variables. 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 like so:

	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
				

Of course you'll need to change the username and password to suit your configuration. With this in place we can start to configure commandbox-migrations. As we've added/updated the .env file we need to reload the shell to pick up the environment variables.

	CommandBox:webroot>reload
	CommandBox:webroot>migrate install
	CommandBox:webroot>migrate create artists
				

This will create a table in your database called cfmigrations and will write a placeholder migrations script in ./resources/database/migrations/ prefixed with the current date/time and suffixed with the name you gave. E.g. artists.

Next you'll need to adapt your placeholder migration script to reflect your database schema design for your table. Take a look at the scripts committed to the repository or this as a simplest example.

	component {
		function up( schema ) {
			schema.create( "artists", function( table ) {
				table.increments( "id" );

				table.string( "name" );
			} );
		}

		function down( schema ) {
			schema.drop( "artists" );
		}
	}
				

To run all the migration scripts you need to:

	CommandBox:webroot>migrate up
				

With that done you should have table in your database called artists with columns that reflect your migrations script definitions.