-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-migration.php
More file actions
46 lines (35 loc) · 1.02 KB
/
create-migration.php
File metadata and controls
46 lines (35 loc) · 1.02 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
<?php
if (php_sapi_name() !== 'cli') {
die("This script can only be run from the command line.\n");
}
if ($argc < 2) {
die("Usage: php create-migration.php 'migration name' [plugin]\n");
}
$migrationName = $argv[1];
$kebabCaseName = strtolower(preg_replace('/[^a-z0-9]+/i', '-', trim($migrationName)));
$timestamp = time();
$fileName = "{$timestamp}-{$kebabCaseName}-migration.php";
$migrationsDir = __DIR__ . '/src/app/migrations';
$pluginDir = null;
if (isset($argv[2])) {
$pluginDir = $argv[2];
}
if ($pluginDir) {
$pluginPath = __DIR__ . "/web/app/plugins/{$pluginDir}";
$migrationsPath = "{$pluginPath}/src/migrations";
if (is_dir($pluginPath)) {
$migrationsDir = $migrationsPath;
}
}
if (!is_dir($migrationsDir)) {
mkdir($migrationsDir, 0755, true);
}
$filePath = $migrationsDir . '/' . $fileName;
$migrationContent = <<<PHP
<?php
return function (\$wpdb) {
throw new Error('Coding...');
};
PHP;
file_put_contents($filePath, $migrationContent);
echo "Migration created at: $filePath\n";