1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Tracking; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
8
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The TableManipulator class is responsible for creating and updating the schema of the table used to track |
12
|
|
|
* the execution state of each migration version. |
13
|
|
|
* |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class TableManipulator |
17
|
|
|
{ |
18
|
|
|
/** @var Configuration */ |
19
|
|
|
private $configuration; |
20
|
|
|
|
21
|
|
|
/** @var AbstractSchemaManager */ |
22
|
|
|
private $schemaManager; |
23
|
|
|
|
24
|
|
|
/** @var TableDefinition */ |
25
|
|
|
private $migrationTable; |
26
|
|
|
|
27
|
|
|
/** @var TableStatus */ |
28
|
|
|
private $migrationTableStatus; |
29
|
|
|
|
30
|
|
|
/** @var TableUpdater */ |
31
|
|
|
private $migrationTableUpdater; |
32
|
|
|
|
33
|
79 |
|
public function __construct( |
34
|
|
|
Configuration $configuration, |
35
|
|
|
AbstractSchemaManager $schemaManager, |
36
|
|
|
TableDefinition $migrationTable, |
37
|
|
|
TableStatus $migrationTableStatus, |
38
|
|
|
TableUpdater $migrationTableUpdater |
39
|
|
|
) { |
40
|
79 |
|
$this->configuration = $configuration; |
41
|
79 |
|
$this->schemaManager = $schemaManager; |
42
|
79 |
|
$this->migrationTable = $migrationTable; |
43
|
79 |
|
$this->migrationTableStatus = $migrationTableStatus; |
44
|
79 |
|
$this->migrationTableUpdater = $migrationTableUpdater; |
45
|
79 |
|
} |
46
|
|
|
|
47
|
79 |
|
public function createMigrationTable() : bool |
48
|
|
|
{ |
49
|
79 |
|
$this->configuration->validate(); |
50
|
|
|
|
51
|
79 |
|
if ($this->configuration->isDryRun()) { |
52
|
1 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
79 |
|
if ($this->migrationTableStatus->isCreated()) { |
56
|
60 |
|
if (! $this->migrationTableStatus->isUpToDate()) { |
57
|
2 |
|
$this->migrationTableUpdater->updateMigrationTable(); |
58
|
|
|
|
59
|
2 |
|
$this->migrationTableStatus->setUpToDate(true); |
60
|
|
|
|
61
|
2 |
|
return true; |
62
|
|
|
} |
63
|
|
|
|
64
|
58 |
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
76 |
|
$table = $this->migrationTable->getNewDBALTable(); |
68
|
|
|
|
69
|
76 |
|
$this->schemaManager->createTable($table); |
70
|
|
|
|
71
|
76 |
|
$this->migrationTableStatus->setCreated(true); |
72
|
|
|
|
73
|
76 |
|
return true; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|