Skip to content

Commit a9bd00a

Browse files
authored
Improve migration docs from ORM 2 to 3. (#12207)
* Improve migration docs from ORM 2 to 3. * Improve wording * Hint about following deprecations.
1 parent 4f3a5c5 commit a9bd00a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

UPGRADE.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
1+
# Upgrade to 3.x General Notes
2+
3+
We recommend you upgrade to DBAL 3 first before upgrading to ORM 3. See
4+
the DBAL upgrade docs: https://github.com/doctrine/dbal/blob/3.10.x/UPGRADE.md
5+
6+
Rather than doing several major upgrades at once, we recommend you do the following:
7+
8+
- upgrade to DBAL 3
9+
- deploy and monitor
10+
- upgrade to ORM 3
11+
- deploy and monitor
12+
- upgrade to DBAL 4
13+
- deploy and monitor
14+
15+
If you are using Symfony, the recommended minimal Doctrine Bundle version is 2.15
16+
to run with ORM 3.
17+
18+
At this point, we recommend upgrading to PHP 8.4 first and then directly from
19+
ORM 2.19 to 3.5 and up so that you can skip the lazy ghost proxy generation
20+
and directly start using native lazy objects.
21+
22+
Note about upgrading: Doctrine uses static and runtime mechanisms to raise
23+
awareness about deprecated code.
24+
25+
- Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or
26+
Static Analysis tools (like Psalm, phpstan)
27+
- Use of our low-overhead runtime deprecation API, details:
28+
https://github.com/doctrine/deprecations/
29+
130
# Upgrade to 3.5
231

32+
See the General notes to upgrading to 3.x versions above.
33+
334
## Deprecate not using native lazy objects on PHP 8.4+
435

536
Having native lazy objects disabled on PHP 8.4+ is deprecated and will not be
@@ -53,6 +84,8 @@ decide to remove it before it is used too widely.
5384

5485
# Upgrade to 3.4
5586

87+
See the General notes to upgrading to 3.x versions above.
88+
5689
## Discriminator Map class duplicates
5790

5891
Using the same class several times in a discriminator map is deprecated.
@@ -73,6 +106,8 @@ Companion accessor methods are deprecated as well.
73106

74107
# Upgrade to 3.3
75108

109+
See the General notes to upgrading to 3.x versions above.
110+
76111
## Deprecate `DatabaseDriver`
77112

78113
The class `Doctrine\ORM\Mapping\Driver\DatabaseDriver` is deprecated without replacement.
@@ -89,6 +124,8 @@ method. Details can be found at https://github.com/doctrine/orm/pull/11188.
89124

90125
# Upgrade to 3.2
91126

127+
See the General notes to upgrading to 3.x versions above.
128+
92129
## Deprecate the `NotSupported` exception
93130

94131
The class `Doctrine\ORM\Exception\NotSupported` is deprecated without replacement.
@@ -115,6 +152,8 @@ using the `\Doctrine\ORM\Mapping\UniqueConstraint` and `\Doctrine\ORM\Mapping\In
115152

116153
# Upgrade to 3.1
117154

155+
See the General notes to upgrading to 3.x versions above.
156+
118157
## Deprecate `Doctrine\ORM\Mapping\ReflectionEnumProperty`
119158

120159
This class is deprecated and will be removed in 4.0.
@@ -138,6 +177,8 @@ Using array access on instances of the following classes is deprecated:
138177

139178
# Upgrade to 3.0
140179

180+
See the General notes to upgrading to 3.x versions above.
181+
141182
## BC BREAK: Calling `ClassMetadata::getAssociationMappedByTargetField()` with the owning side of an association now throws an exception
142183

143184
Previously, calling
@@ -163,6 +204,9 @@ so `$targetEntity` is a first argument now. This change affects only non-named a
163204
When using the `AUTO` strategy to let Doctrine determine the identity generation mechanism for
164205
an entity, and when using `doctrine/dbal` 4, PostgreSQL now uses `IDENTITY`
165206
instead of `SEQUENCE` or `SERIAL`.
207+
208+
There are three ways to handle this change.
209+
166210
* If you want to upgrade your existing tables to identity columns, you will need to follow [migration to identity columns on PostgreSQL](https://www.doctrine-project.org/projects/doctrine-dbal/en/4.0/how-to/postgresql-identity-migration.html)
167211
* If you want to keep using SQL sequences, you need to configure the ORM this way:
168212
```php
@@ -175,6 +219,27 @@ $configuration->setIdentityGenerationPreferences([
175219
PostgreSQLPlatform::CLASS => ClassMetadata::GENERATOR_TYPE_SEQUENCE,
176220
]);
177221
```
222+
* You can change individual entities to use the `SEQUENCE` strategy instead of `AUTO`:
223+
```php
224+
225+
diff --git a/src/Entity/Example.php b/src/Entity/Example.php
226+
index 28be8df378..3b7d61bda6 100644
227+
--- a/src/Entity/Example.php
228+
+++ b/src/Entity/Example.php
229+
@@ -38,7 +38,7 @@ class Example
230+
231+
#[ORM\Id]
232+
#[ORM\Column(type: 'integer')]
233+
- #[ORM\GeneratedValue(strategy: 'AUTO')]
234+
+ #[ORM\GeneratedValue(strategy: 'SEQUENCE')]
235+
private int $id;
236+
237+
#[Assert\Length(max: 255)]
238+
```
239+
The later two options require a small database migration that will remove the default
240+
expression fetching the next value from the sequence. It's not strictly necessary to
241+
do this migration because the code will work anyway. A benefit of this approach is
242+
that you can just make and roll out the code changes first and then migrate the database later.
178243

179244
## BC BREAK: Throw exceptions when using illegal attributes on Embeddable
180245

0 commit comments

Comments
 (0)