-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_migration
More file actions
76 lines (49 loc) · 1.23 KB
/
create_migration
File metadata and controls
76 lines (49 loc) · 1.23 KB
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
<?php
//parent directories
define('DS',DIRECTORY_SEPARATOR);
define('ROOT_PATH',dirname(__FILE__).DS);
define('APP',ROOT_PATH.'app'.DS);
define('PUBLIC_PATH',ROOT_PATH.'public'.DS);
require_once 'app/config/config_constants.php';
require_once 'vendor/autoload.php';
if(php_sapi_name() =='cli')
{
if(isset($argv[1]))
{
$migration_name = $argv[1].'__'.date('Y_m_d_H_i_s',time());
clearstatcache();
// die(MIGRATIONS.$migration_name.'.php');
if(!file_exists(MIGRATIONS.$migration_name.'.php'))
{
file_put_contents(MIGRATIONS.$migration_name.'.php',getMigrationString($migration_name));
die('migration '.$migration_name.'created');
}
else
{
die('migration already exists');
}
}
else
{
die('no data supported to this operation');
}
}
else
{
die('');
}
function getMigrationString($migration_name)
{
$string ='<?php
namespace App\Migrations;
use App\Core\Database\NativeDB;
class '.$migration_name.'{
public function up($db)
{
}
public function down($db)
{
}
}';
return $string;
}