Skip to content

Seeding Data

The seed command has the following structure:

sprout seed [--config=<path>] [--no-chop] [--chop-all] [--group=<group>] [<schema>[:<table>,...]] ...

This will dump the contents of a table to a related file in the specified group as a collection of sql insert statements.

Note

Currently only .sql files are supported when seeding data.

Configuration file

The optional --config option allows you specify the configuration file to use. By default it will look for a file called config/sprout.yml. The location is relative to the working directory. Within docker this is /app.

Prevent truncation

By default the seed command will truncate all the relevant tables. To prevent this you can specify the --no-chop option.

Truncate all the tables

To truncate all the tables in the schema instead of just the tables you want to seed, you can use the option --chop-all. This is the equivalent to the --all option on the chop command.

Schema and Table configuration

All commands make use of the same Schema and Tables parsing.

The [<schema>[:<table>,...]] ... part of the command line allows you to specify none or some schemas, each schema with a set of tables or not.

If no schema is defined, all the schemas and tables in a group will be seeded. If no tables are defined for a schema, all tables on the filesystem will be seeded.

Seeding all the data

You can seed all the current data if you do not specify and schemas or tables.

sprout seed

This will seed all the data in the default group. See groups for more information on how the groups work.

Seeding all the files in a schema

sprout seed schema1

This will chop (truncate) and seed all the tables that exist on the filesystem in the schema: schema1.

You can truncate all the tables in the schema, not just the ones you wish to seed.

sprout seed --chop-all schema1

If you do not wish to truncate the tables first, you can use:

sprout seed --no-chop schema1

You can seed multiple schemas too:

sprout seed schema1 schema2

Seeding specific tables

If you only want to seed a set of specific tables you can specify them as a comma separated list after the schema they apply to.

sprout seed schema1:table1,table2

You can also specify multiple schemas, each with their own set of tables

sprout seed schema1:table1,table2 schema2:table3

Groups

The optional --group option allows you to specify which group to read the seed data from. If this is not supplied it will use the default value as defined in the configuration file.

See Seeding individual groups for more information on how to seed data in groups.

You can see all of the data in a group by calling:

sprout seed --group=testing

Or you can limit it to a set of schemas and tables:

sprout seed --group=testing schema1 schema2:table1,table2