-
Notifications
You must be signed in to change notification settings - Fork 10
/
migrate
178 lines (155 loc) · 5.59 KB
/
migrate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env php
<?php
require __DIR__ .'/vendor/autoload.php';
require __DIR__ .'/config/database.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use Cartalyst\Sentinel\Native\Facades\Sentinel;
class Migrator {
/**
* migrate the database schema
*/
public function migrate() {
/**
* create table for sentinel user
*/
if (!Capsule::schema()->hasTable('users')) {
Capsule::schema()->create('users', function($table)
{
$table->increments('id');
$table->string('email');
$table->string('password');
$table->text('permissions');
$table->timestamp('last_login')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->unique('email');
$table->index('first_name');
$table->index('last_name');
});
}
/**
* create table for sentinel activations
*/
if (!Capsule::schema()->hasTable('activations')) {
Capsule::schema()->create('activations', function($table)
{
$table->increments('id');
$table->integer('user_id');
$table->string('code')->nullable();
$table->tinyInteger('completed')->default(0);
$table->timestamp('completed_at')->nullable();
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->unique('user_id');
});
}
/**
* create persistences table
*/
if (!Capsule::schema()->hasTable('persistences')) {
Capsule::schema()->create('persistences', function($table)
{
$table->increments('id');
$table->integer('user_id');
$table->string('code');
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->unique('code');
});
}
/**
* create reminders table
*/
if (!Capsule::schema()->hasTable('reminders')) {
Capsule::schema()->create('reminders', function($table)
{
$table->increments('id');
$table->integer('user_id');
$table->string('code');
$table->tinyInteger('completed')->default(0);
$table->timestamp('completed_at');
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
});
}
/**
* create roles table
*/
if (!Capsule::schema()->hasTable('roles')) {
Capsule::schema()->create('roles', function($table)
{
$table->increments('id');
$table->string('slug');
$table->string('name');
$table->text('permissions');
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->unique('slug');
});
}
/**
* create role_users table
*/
if (!Capsule::schema()->hasTable('role_users')) {
Capsule::schema()->create('role_users', function($table)
{
$table->integer('user_id');
$table->integer('role_id');
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->primary(array('user_id', 'role_id'));
});
}
/**
* create throttle table
*/
if (!Capsule::schema()->hasTable('throttle')) {
Capsule::schema()->create('throttle', function($table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('type');
$table->string('ip')->nullable();
$table->timestamps();
// We'll need to ensure that MySQL uses the InnoDB engine to
// support the indexes, other engines aren't affected.
$table->engine = 'InnoDB';
$table->unique('user_id');
});
}
}
/**
* seed the database with initial value
*/
public function seed() {
try {
$credentials = [
'email' => '[email protected]',
'password' => 'password',
'first_name' => 'Yudi',
'last_name' => 'Purwanto',
];
$user = Sentinel::registerAndActivate($credentials);
} catch(Exception $e) {
echo $e->getMessage()."\n";
}
}
}
$migrator = new Migrator();
$migrator->migrate();
$migrator->seed();
print("Migration Successfully");