1: <?php
2:
3: class CreateTableUsers extends CakeMigration {
4:
5: 6: 7: 8: 9: 10:
11: public $description = '';
12:
13: 14: 15: 16: 17: 18:
19: public $migration = array(
20: 'up' => array(
21: 'create_table' => array(
22: 'users' => array(
23: 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
24: 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
25: 'email' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
26: 'password' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
27: 'enabled' => array('type' => 'boolean', 'null' => true, 'default' => NULL),
28: 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
29: 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
30: 'indexes' => array(
31: 'PRIMARY' => array('column' => 'id', 'unique' => 1),
32: ),
33: 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
34: ),
35: ),
36: ),
37: 'down' => array(
38: 'drop_table' => array(
39: 'users'
40: )
41: ),
42: );
43:
44: 45: 46: 47: 48: 49: 50:
51: public function before($direction) {
52: return true;
53: }
54:
55: 56: 57: 58: 59: 60: 61:
62: public function after($direction) {
63: if ($direction == 'up') {
64: App::import('Component', 'Auth');
65: $User = $this->generateModel('User');
66: $User->create();
67: $User->save(
68: array(
69: 'email' => 'admin@example.net',
70: 'password' => AuthComponent::password('admin'),
71: 'name' => 'Administrator',
72: 'enabled' => 1,
73: )
74: );
75: }
76: return true;
77: }
78:
79: }
80: