summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Schema/Sequence.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Schema/Sequence.php')
-rw-r--r--vendor/doctrine/dbal/src/Schema/Sequence.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Schema/Sequence.php b/vendor/doctrine/dbal/src/Schema/Sequence.php
new file mode 100644
index 0000000..32a5e67
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Schema/Sequence.php
@@ -0,0 +1,98 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Schema;
6
7use function count;
8use function sprintf;
9
10/**
11 * Sequence structure.
12 */
13class Sequence extends AbstractAsset
14{
15 protected int $allocationSize = 1;
16
17 protected int $initialValue = 1;
18
19 public function __construct(
20 string $name,
21 int $allocationSize = 1,
22 int $initialValue = 1,
23 protected ?int $cache = null,
24 ) {
25 $this->_setName($name);
26 $this->setAllocationSize($allocationSize);
27 $this->setInitialValue($initialValue);
28 }
29
30 public function getAllocationSize(): int
31 {
32 return $this->allocationSize;
33 }
34
35 public function getInitialValue(): int
36 {
37 return $this->initialValue;
38 }
39
40 public function getCache(): ?int
41 {
42 return $this->cache;
43 }
44
45 public function setAllocationSize(int $allocationSize): self
46 {
47 $this->allocationSize = $allocationSize;
48
49 return $this;
50 }
51
52 public function setInitialValue(int $initialValue): self
53 {
54 $this->initialValue = $initialValue;
55
56 return $this;
57 }
58
59 public function setCache(int $cache): self
60 {
61 $this->cache = $cache;
62
63 return $this;
64 }
65
66 /**
67 * Checks if this sequence is an autoincrement sequence for a given table.
68 *
69 * This is used inside the comparator to not report sequences as missing,
70 * when the "from" schema implicitly creates the sequences.
71 */
72 public function isAutoIncrementsFor(Table $table): bool
73 {
74 $primaryKey = $table->getPrimaryKey();
75
76 if ($primaryKey === null) {
77 return false;
78 }
79
80 $pkColumns = $primaryKey->getColumns();
81
82 if (count($pkColumns) !== 1) {
83 return false;
84 }
85
86 $column = $table->getColumn($pkColumns[0]);
87
88 if (! $column->getAutoincrement()) {
89 return false;
90 }
91
92 $sequenceName = $this->getShortestName($table->getNamespaceName());
93 $tableName = $table->getShortestName($table->getNamespaceName());
94 $tableSequenceName = sprintf('%s_%s_seq', $tableName, $column->getShortestName($table->getNamespaceName()));
95
96 return $tableSequenceName === $sequenceName;
97 }
98}