SeedMan (Seed Man v0.1.1)

View Source

Save and load seed data to/from the database as compressed backup files.

Summary

Functions

Dump table data for a given schema_module to a file in the seeds directory priv/repo/seeds.

Load table data for a schema_module from an existing seed data file (to save seed data, see dump_schema_to_seed_file/3).

Read seed data for a given schema module.

Functions

dump_schema_to_seed_file(repo_module, schema_module, opts \\ [])

@spec dump_schema_to_seed_file(module(), module(), keyword()) :: :ok

Dump table data for a given schema_module to a file in the seeds directory priv/repo/seeds.

This function is intended to make it easy to save seed data from an external database so that it can be used to seed local tables during development.

Tip

Before calling this function, ensure that you have started the server with the application configured to use the correct database you want to save the seed data from.

Options

  • :comment - Add a comment to the top of the seed file (e.g. "Hello world!").

  • :seed_data - Specify custom data to dump to the seed file. If this value is not specified, then the full contents of the given schema/table will be dumped as seed data.

Examples

Dump the contents of a given schema/table to a seed file:

iex> SeedMan.dump_schema_to_seed_file(YourProject.Repo, YourProject.Persons.Person)
:ok

Dump the contents of a given schema/table to a seed file with a custom comment embedded in the seed file:

iex> SeedMan.dump_schema_to_seed_file(
...>   YourProject.Repo,
...>   YourProject.Persons.Person,
...>   comment: "For anyone who reads this, X was done because of Y."
...> )
:ok

Dump the contents of the current table to a seed file using custom :seed_data:

iex> SeedMan.dump_schema_to_seed_file(
...>   YourProject.Repo,
...>   YourProject.Persons.Person,
...>   seed_data: [%{...}, %{...}],
...> )
:ok

load_schema_from_seed_file(repo_module, schema_module)

@spec load_schema_from_seed_file(module(), module()) :: :ok

Load table data for a schema_module from an existing seed data file (to save seed data, see dump_schema_to_seed_file/3).

This function is intended to make it easy to load seed data that was previously saved to priv/repo/seeds to make it easier to work with a local database during development.

Tip

Before calling this function, ensure that you have started the server with the application configured to use the correct database you want to load the seed data from.

Examples

iex> SeedMan.load_schema_from_seed_file(YourProject.Repo, YourProject.Persons.Person)
:ok

read_seed_file(schema_module, opts \\ [])

Read seed data for a given schema module.

This function is used to read the seed data before loading it into the database. It is also useful for viewing the contents (including any comments) of seed files.

Options

  • :comment_only? - If true, then just return the comment embedded in the seed file.