Skip to content

Commit e4b92df

Browse files
authored
Merge pull request #235 from javiereguiluz/update_docs
Some updates in the docs for modern Symfony apps
2 parents 4ef56c2 + 37b5ee3 commit e4b92df

File tree

1 file changed

+49
-64
lines changed

1 file changed

+49
-64
lines changed

Resources/doc/index.rst

Lines changed: 49 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,64 @@
11
DoctrineMigrationsBundle
22
========================
33

4-
The database migrations feature is an extension of the database abstraction
5-
layer and offers you the ability to programmatically deploy new versions of
6-
your database schema in a safe, easy and standardized way.
4+
Database migrations are a way to safely update your database schema both locally
5+
and on production. Instead of running the ``doctrine:schema:update`` command or
6+
applying the database changes manually with SQL statements, migrations allow to
7+
replicate the changes in your database schema in a safe manner.
78

8-
.. tip::
9-
10-
You can read more about the Doctrine Database Migrations on the project's
11-
`documentation`_.
9+
Migrations are available in Symfony applications via the `DoctrineMigrationsBundle`_,
10+
which uses the external `Doctrine Database Migrations`_ library. Read the
11+
`documentation`_ of that library if you need a general introduction about migrations.
1212

1313
Installation
1414
------------
1515

16-
Doctrine migrations for Symfony are maintained in the `DoctrineMigrationsBundle`_.
17-
The bundle uses external `Doctrine Database Migrations`_ library.
18-
19-
First, install the bundle with composer:
16+
Run this command in your terminal:
2017

2118
.. code-block:: bash
2219
2320
$ composer require doctrine/doctrine-migrations-bundle "^2.0"
2421
25-
If everything worked, the ``DoctrineMigrationsBundle`` can now be found
26-
at ``vendor/doctrine/doctrine-migrations-bundle``.
27-
28-
.. note::
29-
30-
``DoctrineMigrationsBundle`` installs
31-
`Doctrine Database Migrations`_ library. The library can be found
32-
at ``vendor/doctrine/migrations``.
33-
34-
Finally, be sure to enable the bundle in ``AppKernel.php`` by including the
35-
following:
22+
If you don't use Symfony Flex, you must enable the bundle manually in the application:
3623

3724
.. code-block:: php
3825
39-
// app/AppKernel.php
40-
public function registerBundles()
41-
{
42-
$bundles = array(
43-
//...
44-
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
45-
);
46-
}
26+
// config/bundles.php
27+
// in older Symfony apps, enable the bundle in app/AppKernel.php
28+
return [
29+
// ...
30+
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
31+
];
4732
4833
Configuration
4934
-------------
5035

51-
You can configure the path, namespace, table_name, name, organize_migrations and custom_template in your ``config.yml``. The examples below are the default values.
36+
If you use Symfony Flex, the ``doctrine_migrations.yaml`` config file is created
37+
automatically. Otherwise, create the following file and configure it for your
38+
application:
5239

5340
.. code-block:: yaml
5441
55-
# app/config/config.yml
42+
# config/packages/doctrine_migrations.yaml
5643
doctrine_migrations:
57-
dir_name: "%kernel.root_dir%/Migrations"
58-
namespace: "App\\Migrations"
59-
table_name: "migration_versions"
60-
column_name: "version"
44+
dir_name: '%kernel.project_dir%/src/Migrations'
45+
# namespace is arbitrary but should be different from App\Migrations
46+
# as migrations classes should NOT be autoloaded
47+
namespace: DoctrineMigrations
48+
table_name: 'migration_versions'
49+
column_name: 'version'
6150
column_length: 14
62-
executed_at_column_name: "executed_at"
63-
name: Application Migrations
64-
organize_migrations: false # Version >= 1.2, possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false
65-
custom_template: ~ # Version >= 1.2, path to your custom migrations template
51+
executed_at_column_name: "'executed_at'
52+
name: 'Application Migrations'
53+
# available in version >= 1.2. Possible values: "BY_YEAR", "BY_YEAR_AND_MONTH", false
54+
organize_migrations: false
55+
# available in version >= 1.2. Path to your custom migrations template
56+
custom_template: ~
6657
all_or_nothing: false
6758
6859
Usage
6960
-----
7061

71-
.. caution::
72-
73-
If your application is based on Symfony 3, replace ``php app/console`` by
74-
``php bin/console`` before executing any of the console commands included
75-
in this article.
76-
7762
All of the migrations functionality is contained in a few console commands:
7863

7964
.. code-block:: bash
@@ -95,7 +80,7 @@ the ``status`` command:
9580
9681
.. code-block:: bash
9782
98-
$ php app/console doctrine:migrations:status
83+
$ php bin/console doctrine:migrations:status
9984
10085
== Configuration
10186
@@ -123,7 +108,7 @@ for you.
123108
124109
.. code-block:: bash
125110
126-
$ php app/console doctrine:migrations:generate
111+
$ php bin/console doctrine:migrations:generate
127112
Generated new migration class to "/path/to/project/app/Migrations/Version20180605025653.php"
128113
129114
To run just this migration for testing purposes, you can use migrations:execute --up 20180605025653
@@ -168,7 +153,7 @@ migration to execute:
168153
169154
.. code-block:: bash
170155
171-
$ php app/console doctrine:migrations:status --show-versions
156+
$ php bin/console doctrine:migrations:status --show-versions
172157
173158
== Configuration
174159
@@ -199,7 +184,7 @@ finally migrate when you're ready:
199184
200185
.. code-block:: bash
201186
202-
$ php app/console doctrine:migrations:migrate 20180605025653
187+
$ php bin/console doctrine:migrations:migrate 20180605025653
203188
204189
For more information on how to write the migrations themselves (i.e. how to
205190
fill in the ``up()`` and ``down()`` methods), see the official Doctrine Migrations
@@ -226,11 +211,11 @@ been run yet on *that* particular database.
226211
Skipping Migrations
227212
~~~~~~~~~~~~~~~~~~~
228213
229-
You can skip single migrations by explicitely adding them to the ``migration_versions`` table:
214+
You can skip single migrations by explicitly adding them to the ``migration_versions`` table:
230215
231216
.. code-block:: bash
232217
233-
$ php app/console doctrine:migrations:version YYYYMMDDHHMMSS --add
218+
$ php bin/console doctrine:migrations:version YYYYMMDDHHMMSS --add
234219
235220
Doctrine will then assume that this migration has already been run and will ignore it.
236221
@@ -249,8 +234,8 @@ for Doctrine's ORM:
249234
250235
.. code-block:: php-annotations
251236
252-
// src/Acme/HelloBundle/Entity/User.php
253-
namespace Acme\HelloBundle\Entity;
237+
// src/Entity/User.php
238+
namespace App\Entity;
254239
255240
use Doctrine\ORM\Mapping as ORM;
256241
@@ -274,10 +259,10 @@ for Doctrine's ORM:
274259
275260
.. code-block:: yaml
276261
277-
# src/Acme/HelloBundle/Resources/config/doctrine/User.orm.yml
278-
Acme\HelloBundle\Entity\User:
262+
# config/doctrine/User.orm.yml
263+
App\Entity\User:
279264
type: entity
280-
table: hello_user
265+
table: user
281266
id:
282267
id:
283268
type: integer
@@ -290,13 +275,13 @@ for Doctrine's ORM:
290275
291276
.. code-block:: xml
292277
293-
<!-- src/Acme/HelloBundle/Resources/config/doctrine/User.orm.xml -->
278+
<!-- config/doctrine/User.orm.xml -->
294279
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
295280
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
296281
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
297282
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
298283
299-
<entity name="Acme\HelloBundle\Entity\User" table="hello_user">
284+
<entity name="App\Entity\User" table="user">
300285
<id name="id" type="integer" column="id">
301286
<generator strategy="AUTO"/>
302287
</id>
@@ -306,22 +291,22 @@ for Doctrine's ORM:
306291
</doctrine-mapping>
307292
308293
With this information, Doctrine is now ready to help you persist your new
309-
``User`` object to and from the ``hello_user`` table. Of course, this table
294+
``User`` object to and from the ``user`` table. Of course, this table
310295
doesn't exist yet! Generate a new migration for this table automatically by
311296
running the following command:
312297
313298
.. code-block:: bash
314299
315-
$ php app/console doctrine:migrations:diff
300+
$ php bin/console doctrine:migrations:diff
316301
317302
You should see a message that a new migration class was generated based on
318303
the schema differences. If you open this file, you'll find that it has the
319-
SQL code needed to create the ``hello_user`` table. Next, run the migration
304+
SQL code needed to create the ``user`` table. Next, run the migration
320305
to add the table to your database:
321306
322307
.. code-block:: bash
323308
324-
$ php app/console doctrine:migrations:migrate
309+
$ php bin/console doctrine:migrations:migrate
325310
326311
The moral of the story is this: after each change you make to your Doctrine
327312
mapping information, run the ``doctrine:migrations:diff`` command to automatically
@@ -338,7 +323,7 @@ If you don't want to use this workflow and instead create your schema via
338323
339324
.. code-block:: bash
340325
341-
$ php app/console doctrine:migrations:version --add --all
326+
$ php bin/console doctrine:migrations:version --add --all
342327
343328
Otherwise Doctrine will try to run all migrations, which probably will not work.
344329

0 commit comments

Comments
 (0)