[migrations]
link in the debug footer to load the built in GUI. Naturally, you will need your application's datasource setup and ready to go to get started.Timestamp
and Numeric
is perfectly valid, but we recommend the Timestamp
prefix if you're just starting out. Once you have a migration file, this section will disappear as it will get that info from the existing files.users
table. So under Create a Template
, we will select Create table
and add a migration description of Create User Table
.Create Migration File
will then create a CFC at /db/migrate/20170420100502_Create_User_Table.cfc
. The system will also display all messages at the top of the GUI whenever it does something - so for this command, we see The migration 20170420100502_Create_User_Table.cfc file was created
Create_User_Table.cfc
template we just created. There are two functions to any migration file: up()
and down()
.up()
will be executed when migrating your schema forward, and down()
when you're rolling back.up()
function will look something like this. Most of it you can actually ignore, as it's just wrapped in a transaction with some error handling. The important lines to look at are:createTable()
is the command to actually make the table: so we need to change this to users
.t.create();
is the final statement which executes the actual action.down()
function needs to reverse these changes. so in our down()
code block, we're going to change the dropTable('tableName');
to `dropTable('users');firstname
. Here's an example of a slightly more fleshed out migration file to give you some inspiration:t = createTable(name='users');
will create a standard auto-increment numeric ID, sometimes you need to create a table which has a composite, or non standard primary key. In this example, we're setting id=false
on the createTable()
call to bypass the default behavior, then specifying our primarykeys seperately via primaryKey()
:0
.