-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmigrate.php
More file actions
39 lines (32 loc) · 1.21 KB
/
Copy pathmigrate.php
File metadata and controls
39 lines (32 loc) · 1.21 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
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use BBS\Core\Migrator;
$migrator = new Migrator();
$ran = $migrator->run();
foreach ($ran as $file) {
echo "Migrated: {$file}\n";
}
// Statements stepped over because the change was already present. Normal on a
// fresh install, where schema.sql has already created most of it.
foreach ($migrator->skipped as $skip) {
echo "Already applied: {$skip}\n";
}
if (!empty($migrator->errors)) {
// Loud, and a non-zero exit. These migrations were NOT recorded and will
// be retried on the next run; until one succeeds the schema is not what
// the code expects. Reporting this as a routine skip is what let a
// half-applied migration pass for a clean one.
fwrite(STDERR, "\nMIGRATION FAILED — the database is not fully up to date:\n");
foreach ($migrator->errors as $err) {
fwrite(STDERR, " ✗ {$err}\n");
}
fwrite(STDERR, "\nThese will be retried on the next update. If one keeps failing,\n"
. "the message above names the statement that could not be applied.\n");
exit(1);
}
if (empty($ran) && empty($migrator->skipped)) {
echo "Nothing to migrate.\n";
} else {
echo "Done.\n";
}