Migrator Migration Functions TableDefinition migration
Creates a table definition object to store table properties Only available in a migration CFC
Name | Type | Required | Default | Description |
---|---|---|---|---|
name | string | Yes | The name of the table to create | |
force | boolean | No | false | whether to drop the table before creating it |
id | boolean | No | true | Whether to create a default primarykey or not |
primaryKey | string | No | id | Name of the primary key field to create |
// Example: create a users table
t = createTable(name='users');
t.string(columnNames='firstname,lastname', default='', null=false, limit=50);
t.string(columnNames='email', default='', null=false, limit=255);
t.string(columnNames='passwordHash', default='', null=true, limit=500);
t.string(columnNames='passwordResetToken,verificationToken', default='', null=true, limit=500);
t.boolean(columnNames='passwordChangeRequired,verified', default=false);
t.datetime(columnNames='passwordResetTokenAt,passwordResetAt,loggedinAt', default='', null=true);
t.integer(columnNames='roleid', default=0, null=false, limit=3);
t.timestamps();
t.create();
// Example: Create a table with a different Primary Key
t = createTable(name='tokens', id=false);
t.primaryKey(name='id', null=false, type="string", limit=35 );
t.datetime(columnNames="expiresAt", null=false);
t.integer(columnNames='requests', default=0, null=false);
t.timestamps();
t.create();
// Example: Create a Join Table with composite primary keys
t = createTable(name='userkintins', id=false);
t.primaryKey(name="userid", null=false, limit=11);
t.primaryKey(name='profileid', type="string", limit=11 );
t.create();