|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Column; |
|
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
9
|
|
|
use Doctrine\DBAL\Types\Type; |
|
10
|
|
|
|
|
11
|
|
|
class MigrationTable |
|
12
|
|
|
{ |
|
13
|
|
|
public const MIGRATION_COLUMN_TYPE = 'string'; |
|
14
|
|
|
public const MIGRATION_EXECUTED_AT_COLUMN_TYPE = 'datetime_immutable'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string */ |
|
17
|
|
|
private $name; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $columnName; |
|
21
|
|
|
|
|
22
|
|
|
/** @var int */ |
|
23
|
|
|
private $columnLength; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $executedAtColumnName; |
|
27
|
|
|
|
|
28
|
82 |
|
public function __construct( |
|
29
|
|
|
string $name, |
|
30
|
|
|
string $columnName, |
|
31
|
|
|
int $columnLength, |
|
32
|
|
|
string $executedAtColumnName |
|
33
|
|
|
) { |
|
34
|
82 |
|
$this->name = $name; |
|
35
|
82 |
|
$this->columnName = $columnName; |
|
36
|
82 |
|
$this->columnLength = $columnLength; |
|
37
|
82 |
|
$this->executedAtColumnName = $executedAtColumnName; |
|
38
|
82 |
|
} |
|
39
|
|
|
|
|
40
|
69 |
|
public function getName() : string |
|
41
|
|
|
{ |
|
42
|
69 |
|
return $this->name; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
69 |
|
public function getColumnName() : string |
|
46
|
|
|
{ |
|
47
|
69 |
|
return $this->columnName; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function getColumnLength() : int |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->columnLength; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function getExecutedAtColumnName() : string |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->executedAtColumnName; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
75 |
|
public function getMigrationsColumn() : Column |
|
61
|
|
|
{ |
|
62
|
75 |
|
return new Column( |
|
63
|
75 |
|
$this->columnName, |
|
64
|
75 |
|
Type::getType(self::MIGRATION_COLUMN_TYPE), |
|
65
|
75 |
|
['length' => $this->columnLength] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
75 |
|
public function getExecutedAtColumn() : Column |
|
70
|
|
|
{ |
|
71
|
75 |
|
return new Column( |
|
72
|
75 |
|
$this->executedAtColumnName, |
|
73
|
75 |
|
Type::getType(self::MIGRATION_EXECUTED_AT_COLUMN_TYPE) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return string[] |
|
79
|
|
|
*/ |
|
80
|
55 |
|
public function getColumnNames() : array |
|
81
|
|
|
{ |
|
82
|
|
|
return [ |
|
83
|
55 |
|
$this->columnName, |
|
84
|
55 |
|
$this->executedAtColumnName, |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
2 |
|
public function getDBALTable() : Table |
|
89
|
|
|
{ |
|
90
|
2 |
|
$executedAtColumn = $this->getExecutedAtColumn(); |
|
91
|
2 |
|
$executedAtColumn->setNotnull(false); |
|
92
|
|
|
|
|
93
|
2 |
|
return $this->createDBALTable($executedAtColumn); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
66 |
|
public function getNewDBALTable() : Table |
|
97
|
|
|
{ |
|
98
|
66 |
|
$executedAtColumn = $this->getExecutedAtColumn(); |
|
99
|
66 |
|
$executedAtColumn->setNotnull(true); |
|
100
|
|
|
|
|
101
|
66 |
|
return $this->createDBALTable($executedAtColumn); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
68 |
|
private function createDBALTable(Column $executedAtColumn) : Table |
|
105
|
|
|
{ |
|
106
|
|
|
$columns = [ |
|
107
|
68 |
|
$this->columnName => $this->getMigrationsColumn(), |
|
108
|
68 |
|
$this->executedAtColumnName => $executedAtColumn, |
|
109
|
|
|
]; |
|
110
|
|
|
|
|
111
|
68 |
|
$table = new Table($this->getName(), $columns); |
|
112
|
68 |
|
$table->setPrimaryKey([$this->getColumnName()]); |
|
113
|
|
|
|
|
114
|
68 |
|
return $table; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|