|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
|
4
|
|
|
|
|
5
|
|
|
class AdminUsers extends AbstractMigration |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
public function up() |
|
8
|
|
|
{ |
|
9
|
|
|
$this->table('admin_users', ['id' => false, 'primary_key' => 'admin_user_uuid']) |
|
10
|
|
|
->addColumn('admin_user_uuid', 'binary', ['limit' => 16]) |
|
11
|
|
|
->addColumn('first_name', 'text') |
|
12
|
|
|
->addColumn('last_name', 'text') |
|
13
|
|
|
->addColumn('email', 'string', ['limit' => 128]) |
|
14
|
|
|
->addColumn('password', 'char', ['limit' => 60]) |
|
15
|
|
|
->addColumn('status', 'integer', ['default' => 0])// 0 => not active, 1 = active |
|
16
|
|
|
->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) |
|
17
|
|
|
->addColumn('last_login', 'datetime', ['null' => true]) |
|
18
|
|
|
->addIndex(['email'], ['name' => 'email_INDEX']) |
|
19
|
|
|
->create(); |
|
20
|
|
|
|
|
21
|
|
|
$faker = Faker\Factory::create(); |
|
22
|
|
|
$count = rand(100, 150); |
|
23
|
|
|
for($i = 0; $i < $count; $i++){ |
|
24
|
|
|
$data = [ |
|
25
|
|
|
'admin_user_uuid' => $faker->uuid, |
|
26
|
|
|
'email' => $faker->email, |
|
27
|
|
|
'first_name' => $faker->firstName, |
|
28
|
|
|
'last_name' => $faker->lastName, |
|
29
|
|
|
'password' => '$2y$10$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK',//password = testtest |
|
30
|
|
|
'status' => rand(0, 1), |
|
31
|
|
|
'last_login' => rand(0, 10) === 7 ? null : $faker->dateTimeBetween('-10 days', 'now')->format('Y-m-d H:i:s'), |
|
32
|
|
|
'created_at' => $faker->dateTimeBetween('-20 days', '-10 days')->format('Y-m-d H:i:s'), |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
$this->insert('admin_users', $data); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// Insert default user with password testtest |
|
39
|
|
|
$this->execute( |
|
40
|
|
|
"insert into admin_users (admin_user_uuid, first_name,last_name,email,password, status) values " . |
|
41
|
|
|
"('$faker->uuid', 'Unfinished', 'Admin', '[email protected]', '$2y$10\$jhGH8RXl269ho1CrLaDiregVuW84HegLHmBFUCKTgDQTH2XgPZyBK', 1)" |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function down() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->dropTable('admin_users'); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.