Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions docs/en/seeding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Migrations includes a command to easily generate a new seed class:

.. code-block:: bash

$ bin/cake bake seed MyNewSeed
bin/cake bake seed MyNewSeed

By default, it generates a traditional seed class with a named class:

Expand Down Expand Up @@ -75,7 +75,7 @@ To generate an anonymous seed class, use the ``--style anonymous`` option:

.. code-block:: bash

$ bin/cake bake seed MyNewSeed --style anonymous
bin/cake bake seed MyNewSeed --style anonymous

This generates a seed file using an anonymous class:

Expand Down Expand Up @@ -114,10 +114,11 @@ You can set the default seed style globally in your application configuration:
'style' => 'anonymous', // or 'traditional'
],

Seed Options
------------
Additional option
Copy link
Member

@dereuromark dereuromark Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Additional option
Additional options

maybe

-----------------

.. code-block:: bash

# You specify the name of the table the seed files will alter by using the ``--table`` option
bin/cake bake seed Articles --table my_articles_table

Expand Down Expand Up @@ -155,7 +156,7 @@ include as a comma separated value string:
.. _custom-seed-migration-templates:

Customizing Seed and Migration templates
----------------------------------------
========================================

Because migrations uses `bake <https://book.cakephp.org/bake>`__ under the hood
you can customize the templates that migrations uses for creating seeds and
Expand All @@ -178,7 +179,7 @@ It provides the necessary support to create your seed classes. Seed
classes are primarily used to insert test data.

The Run Method
==============
--------------

The run method is automatically invoked by Migrations when you execute the
``cake migration seed`` command. You should use this method to insert your test
Expand All @@ -191,21 +192,21 @@ data.
mind when developing them.

The Init Method
===============
---------------

The ``init()`` method is run by Migrations before the run method if it exists. This
can be used to initialize properties of the Seed class before using run.

The Should Execute Method
=========================
-------------------------

The ``shouldExecute()`` method is run by Migrations before executing the seed.
This can be used to prevent the seed from being executed at this time. It always
returns true by default. You can override it in your custom ``BaseSeed``
implementation.

Foreign Key Dependencies
========================
------------------------

Often you'll find that seeds need to run in a particular order, so they don't
violate foreign key constraints. To define this order, you can implement the
Expand Down Expand Up @@ -375,33 +376,37 @@ This is the easy part. To seed your database, simply use the ``migrations seed``

.. code-block:: bash

$ bin/cake migrations seed
bin/cake migrations seed

By default, Migrations will execute all available seed classes. If you would like to
run a specific class, simply pass in the name of it using the ``--seed`` parameter.
You can use either the short name (without the ``Seed`` suffix) or the full name:

.. code-block:: bash

$ bin/cake migrations seed --seed User
# or
$ bin/cake migrations seed --seed UserSeed
# One of
bin/cake migrations seed --seed User
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should IMO remove the option part for the major, it become superfluous and will only bloat docs and maybe confuse people in the long run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, afaik I did that already ( https://github.com/cakephp/migrations/pull/935/files )
I must have been forgetting the docs update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be breaking compatibility just for fun.

Copy link
Member

@dereuromark dereuromark Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats not for fun
The current way is bonkers and completely wrong
The major allows this cleanup - as with all other commands the subset (one specific) of all is an argument never an option. E.g. bake.

bin/cake migrations seed --seed UserSeed
bin/cake migrations seed User

Both commands work identically.

You can also run multiple seeds:

.. code-block:: bash

$ bin/cake migrations seed --seed User --seed Permission --seed Log
# or with full names
$ bin/cake migrations seed --seed UserSeed --seed PermissionSeed --seed LogSeed
# Multiple --seed options
bin/cake migrations seed --seed User --seed Permission --seed Log
# or with full names
bin/cake migrations seed --seed UserSeed --seed PermissionSeed --seed LogSeed
# Or an interactive prompt for all


You can also use the `-v` parameter for more output verbosity:
You can also use the ``-v`` parameter for more output verbosity:

.. code-block:: bash

$ bin/cake migrations seed -v
bin/cake migrations seed -v

The Migrations seed functionality provides a simple mechanism to easily and repeatably
insert test data into your database, this is great for development environment
Expand Down
Loading