-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_schemas.php
More file actions
47 lines (32 loc) · 1.1 KB
/
migrate_schemas.php
File metadata and controls
47 lines (32 loc) · 1.1 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
<?php
declare(strict_types=1);
use BLInc\Migration\SchemaLoader;
use BLInc\Migration\SchemaTool;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
require_once __DIR__ . '/app/bootstrap.php';
$applyMigrations = ($argc === 2 && $argv[1] === '--force');
$migrateSchema = function (Schema $schema, Connection $connection, $applyMigrations) {
$queries = (new SchemaTool($connection))->generateSql($schema);
$queryCount = 0;
echo "Queries To Run\n\n";
foreach ($queries as $query) {
$queryCount++;
echo $query . "\n";
if ($applyMigrations) {
$connection->exec($query);
}
}
if ($queryCount === 0) {
echo "No Migration Needed!\n";
return;
}
echo "\n";
};
$schemaLoader = new SchemaLoader();
/** @var Connection $primaryConnection */
$primaryConnection = $app['db'];
$migrateSchema($schemaLoader->getPrimarySchema(), $primaryConnection, $applyMigrations);
/** @var Connection $logConnection */
$logConnection = $app['dbs']['log'];
$migrateSchema($schemaLoader->getLogSchema(), $logConnection, $applyMigrations);