Skip to content

Commit b3fb126

Browse files
committed
Remove deprecated Sequence features
1 parent f6f984c commit b3fb126

13 files changed

+87
-145
lines changed

UPGRADE.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ awareness about deprecated code.
88

99
# Upgrade to 5.0
1010

11+
## BC BREAK: Changes in `Sequence` API
12+
13+
The following `Sequence` methods have been removed:
14+
15+
- `Sequence::getCache()`
16+
- `Sequence::setAllocationSize()`
17+
- `Sequence::setInitialValue()`
18+
- `Sequence::setCache()`
19+
20+
Additionally, the `Sequence` class has been declared as final.
21+
1122
## BC BREAK: Removed `AbstractAsset` class
1223

1324
The `AbstractAsset` class has been removed.
@@ -88,7 +99,6 @@ The following classes have been marked as final:
8899
- `ColumnDiff`
89100
- `Table`
90101
- `TableDiff`
91-
- `Sequence`
92102
- `Schema`
93103
- `SchemaDiff`
94104
- `View`

src/Platforms/OraclePlatform.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,12 @@ private function getCreateAutoincrementSql(OptionallyQualifiedName $tableName, U
363363

364364
$triggerName = $this->generateAutoincrementTriggerName($tableName->getUnqualifiedName());
365365
$sequenceName = $this->generateAutoincrementSequenceName($tableName);
366-
$sequence = new Sequence($sequenceName->toString());
367-
$sql[] = $this->getCreateSequenceSQL($sequence);
366+
367+
$sequence = Sequence::editor()
368+
->setName($sequenceName)
369+
->create();
370+
371+
$sql[] = $this->getCreateSequenceSQL($sequence);
368372

369373
$sql[] = sprintf(
370374
<<<'SQL'

src/Platforms/PostgreSQLPlatform.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ public function getListDatabasesSQL(): string
149149
/** @internal The method should be only used from within the {@see AbstractSchemaManager} class hierarchy. */
150150
public function getListSequencesSQL(string $database): string
151151
{
152-
return 'SELECT sequence_name AS relname,
153-
sequence_schema AS schemaname,
154-
minimum_value AS min_value,
155-
increment AS increment_by
152+
return 'SELECT sequence_name,
153+
sequence_schema,
154+
minimum_value,
155+
increment
156156
FROM information_schema.sequences
157157
WHERE sequence_catalog = ' . $this->quoteStringLiteral($database) . "
158158
AND sequence_schema NOT LIKE 'pg\_%'

src/Platforms/SQLServerPlatform.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ public function getCreateSequenceSQL(Sequence $sequence): string
153153
public function getListSequencesSQL(string $database): string
154154
{
155155
return 'SELECT seq.name,
156+
scm.name AS schema_name,
156157
CAST(
157158
seq.increment AS VARCHAR(MAX)
158159
) AS increment, -- CAST avoids driver error for sql_variant type
159160
CAST(
160161
seq.start_value AS VARCHAR(MAX)
161162
) AS start_value -- CAST avoids driver error for sql_variant type
162-
FROM sys.sequences AS seq';
163+
FROM sys.sequences AS seq
164+
JOIN sys.schemas AS scm
165+
ON scm.schema_id = seq.schema_id';
163166
}
164167

165168
public function getSequenceNextValSQL(string $sequence): string

src/Schema/OracleSchemaManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ protected function _getPortableSequenceDefinition(array $sequence): Sequence
212212
{
213213
$sequence = array_change_key_case($sequence, CASE_LOWER);
214214

215-
return new Sequence(
216-
$this->getQuotedIdentifierName($sequence['sequence_name']),
217-
(int) $sequence['increment_by'],
218-
(int) $sequence['min_value'],
219-
);
215+
return Sequence::editor()
216+
->setQuotedName($sequence['sequence_name'])
217+
->setAllocationSize((int) $sequence['increment_by'])
218+
->setInitialValue((int) $sequence['min_value'])
219+
->create();
220220
}
221221

222222
/**

src/Schema/PostgreSQLSchemaManager.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,17 @@ protected function _getPortableDatabaseDefinition(array $database): string
166166
protected function _getPortableSequenceDefinition(array $sequence): Sequence
167167
{
168168
// @phpstan-ignore missingType.checkedException
169-
if ($sequence['schemaname'] !== $this->getCurrentSchemaName()) {
170-
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
169+
if ($sequence['sequence_schema'] !== $this->getCurrentSchemaName()) {
170+
$name = OptionallyQualifiedName::quoted($sequence['sequence_name'], $sequence['sequence_schema']);
171171
} else {
172-
$sequenceName = $sequence['relname'];
172+
$name = OptionallyQualifiedName::quoted($sequence['sequence_name']);
173173
}
174174

175-
return new Sequence($sequenceName, (int) $sequence['increment_by'], (int) $sequence['min_value']);
175+
return Sequence::editor()
176+
->setName($name)
177+
->setAllocationSize((int) $sequence['increment'])
178+
->setInitialValue((int) $sequence['minimum_value'])
179+
->create();
176180
}
177181

178182
/**

src/Schema/SQLServerSchemaManager.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ public function listSchemaNames(): array
4646
*/
4747
protected function _getPortableSequenceDefinition(array $sequence): Sequence
4848
{
49-
return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']);
49+
// @phpstan-ignore missingType.checkedException
50+
if ($sequence['schema_name'] !== $this->getCurrentSchemaName()) {
51+
$name = OptionallyQualifiedName::quoted($sequence['name'], $sequence['schema_name']);
52+
} else {
53+
$name = OptionallyQualifiedName::quoted($sequence['name']);
54+
}
55+
56+
return Sequence::editor()
57+
->setName($name)
58+
->setAllocationSize((int) $sequence['increment'])
59+
->setInitialValue((int) $sequence['start_value'])
60+
->create();
5061
}
5162

5263
/**

src/Schema/Schema.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,20 @@ public function dropTable(string $name): self
390390
*/
391391
public function createSequence(string $name, int $allocationSize = 1, int $initialValue = 1): Sequence
392392
{
393-
$seq = new Sequence($name, $allocationSize, $initialValue);
393+
$parser = Parsers::getOptionallyQualifiedNameParser();
394+
395+
try {
396+
$parsedName = $parser->parse($name);
397+
} catch (Parser\Exception $e) {
398+
throw InvalidName::fromParserException($name, $e);
399+
}
400+
401+
$seq = Sequence::editor()
402+
->setName($parsedName)
403+
->setAllocationSize($allocationSize)
404+
->setInitialValue($initialValue)
405+
->create();
406+
394407
$this->addSequence($seq);
395408

396409
return $seq;

src/Schema/Sequence.php

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7-
use Doctrine\DBAL\Schema\Exception\InvalidName;
7+
use Doctrine\DBAL\Schema\Exception\InvalidSequenceDefinition;
88
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
9-
use Doctrine\DBAL\Schema\Name\Parser;
10-
use Doctrine\DBAL\Schema\Name\Parsers;
11-
use Doctrine\Deprecations\Deprecation;
129

1310
/**
1411
* Sequence structure.
@@ -17,42 +14,23 @@
1714
*/
1815
final class Sequence extends AbstractNamedObject
1916
{
20-
private int $allocationSize = 1;
21-
22-
private int $initialValue = 1;
23-
2417
/**
2518
* @internal Use {@link Sequence::editor()} to instantiate an editor and {@link SequenceEditor::create()} to create
2619
* a sequence.
2720
*
28-
* @param ?non-negative-int $cache
21+
* @param ?non-negative-int $cacheSize
2922
*/
3023
public function __construct(
31-
string $name,
32-
int $allocationSize = 1,
33-
int $initialValue = 1,
34-
private ?int $cache = null,
24+
OptionallyQualifiedName $name,
25+
private readonly int $allocationSize,
26+
private readonly int $initialValue,
27+
private readonly ?int $cacheSize = null,
3528
) {
36-
$parser = Parsers::getOptionallyQualifiedNameParser();
29+
parent::__construct($name);
3730

38-
try {
39-
$parsedName = $parser->parse($name);
40-
} catch (Parser\Exception $e) {
41-
throw InvalidName::fromParserException($name, $e);
31+
if ($cacheSize < 0) {
32+
throw InvalidSequenceDefinition::fromNegativeCacheSize($cacheSize);
4233
}
43-
44-
parent::__construct($parsedName);
45-
46-
if ($cache < 0) {
47-
Deprecation::triggerIfCalledFromOutside(
48-
'doctrine/dbal',
49-
'https://github.com/doctrine/dbal/pull/7108',
50-
'Passing a negative value as sequence cache size is deprecated.',
51-
);
52-
}
53-
54-
$this->setAllocationSize($allocationSize);
55-
$this->setInitialValue($initialValue);
5634
}
5735

5836
public function getAllocationSize(): int
@@ -65,49 +43,10 @@ public function getInitialValue(): int
6543
return $this->initialValue;
6644
}
6745

68-
/**
69-
* @deprecated Use {@see getCacheSize()} instead.
70-
*
71-
* @return ?non-negative-int
72-
*/
73-
public function getCache(): ?int
74-
{
75-
Deprecation::triggerIfCalledFromOutside(
76-
'doctrine/dbal',
77-
'https://github.com/doctrine/dbal/pull/7108',
78-
'%s is deprecated, use `getCacheSize()` instead.',
79-
__METHOD__,
80-
);
81-
82-
return $this->cache;
83-
}
84-
8546
/** @return ?non-negative-int */
8647
public function getCacheSize(): ?int
8748
{
88-
return $this->getCache();
89-
}
90-
91-
public function setAllocationSize(int $allocationSize): self
92-
{
93-
$this->allocationSize = $allocationSize;
94-
95-
return $this;
96-
}
97-
98-
public function setInitialValue(int $initialValue): self
99-
{
100-
$this->initialValue = $initialValue;
101-
102-
return $this;
103-
}
104-
105-
/** @param non-negative-int $cache */
106-
public function setCache(int $cache): self
107-
{
108-
$this->cache = $cache;
109-
110-
return $this;
49+
return $this->cacheSize;
11150
}
11251

11352
/**
@@ -124,9 +63,9 @@ public static function editor(): SequenceEditor
12463
public function edit(): SequenceEditor
12564
{
12665
return self::editor()
127-
->setName($this->getObjectName())
128-
->setAllocationSize($this->getAllocationSize())
129-
->setInitialValue($this->getInitialValue())
130-
->setCacheSize($this->getCacheSize());
66+
->setName($this->name)
67+
->setAllocationSize($this->allocationSize)
68+
->setInitialValue($this->initialValue)
69+
->setCacheSize($this->cacheSize);
13170
}
13271
}

src/Schema/SequenceEditor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function create(): Sequence
8585
}
8686

8787
return new Sequence(
88-
$this->name->toString(),
88+
$this->name,
8989
$this->allocationSize,
9090
$this->initialValue,
9191
$this->cacheSize,

0 commit comments

Comments
 (0)