Skip to content
fireproofsocks edited this page Dec 11, 2014 · 2 revisions

seed

Use the seed function to add records to your database. This is how you can add resources, actions, menus, or any supported MODX object into your database. This can also be used to load test data.

Usage:

php repoman seed <pkg_root_dir> [options]

The objects can be stored as PHP or JSON arrays. The filename must reference the object classname via the following syntax:

[ordering-prefix.]classname.php|json

An optional identifier prefix can come before the classname, e.g. 001-Red-Sweater.Product.php. This is useful if you need to force the seeds to be loaded in a specific order. Set the "packages" array with any custom packages to make them available to the seed command.

A seed file may contain a single object or an array of objects (i.e. a recordset). Use the export command to export existing database records to the filesystem for use via a seed command.

Although you may add Elements (Snippets, Chunks, Templates, and Plugins) to your database via a seeding operation, those objects are better managed via the import command and referenced as files.

Parameters:

`--seeds_path` :  dir (or dirs) relative to package root containing seed data. In your
    composer.json file, this will be an array.  On the command-line, you may supply a
    comma-separated string, e.g.

        php repoman seed <pkg_root_dir> --seeds_path=model/seeds/base/,model/seeds/test1/

`--overwrite` : if set, existing objects will be rewritten regardless of their build attribute
    settings.

Build Attributes:

Database seeding respects the xPDOTransport::UPDATE_OBJECT build attribute for the classnames involved. This is important so that some records do not get overwritten after they are first created: use the overwrite option to force updates during repeated seed operations.

When migrating custom data for custom tables you must define a node in the "build_attributes" array in your package's composer.json file, e.g.

    "extra": {
        "build_attributes":{
            "Currency": {
                "preserve_keys":true,
                "update_object":true,
                "unique_key":true
            }
    }

You should list any custom packages in the "packages" section of your composer.json.

Clone this wiki locally