Skip to content

Instantly share code, notes, and snippets.

@n0mad01
Last active October 9, 2015 15:25
Show Gist options
  • Save n0mad01/5d44a845659e64ba506a to your computer and use it in GitHub Desktop.
Save n0mad01/5d44a845659e64ba506a to your computer and use it in GitHub Desktop.
CakePHP 3 Sessions Table Migration
this:
-----
CREATE TABLE sessions (
id varchar(40) NOT NULL default '',
data text,
expires INT(11) NOT NULL,
PRIMARY KEY (id)
);
equals:
-------
$ bin/cake bake migration CreateSessions id:string:primary data:text expires:integer
equals:
-------
<?php
use Migrations\AbstractMigration;
class CreateSessions extends AbstractMigration
{
public $autoId = false;
public function change()
{
$table = $this->table('sessions');
$table->addColumn('id', 'string', [
'default' => null,
'limit' => 40,
'null' => false,
]);
$table->addColumn('data', 'text', [
'default' => null,
'null' => false,
]);
$table->addColumn('expires', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addPrimaryKey([
'id',
]);
$table->create();
}
}
$ bin/cake migrations migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment