botanist v0.1.2 Botanist View Source

Botanist is a seeding library which uses Ecto. Its intended purpose is for seeding of a database in a safe and atomic manner.

Link to this section Summary

Functions

Macro for seeds which can be run recurrently. Functionally equivilant to seed/1 but will run every time mix ecto.seed is called

Macro for seeding the database. No seed can be run more than once. If extra data is to be added or removed, a new seed must be generated with mix ecto.gen.seed or use perennial_seed/1

Link to this section Functions

Link to this macro perennial_seed(list) View Source (macro)

Macro for seeds which can be run recurrently. Functionally equivilant to seed/1 but will run every time mix ecto.seed is called.

Example

import Botanist

def planter do
  perennial_seed do
    # Recurrent work here
  end
end

Macro for seeding the database. No seed can be run more than once. If extra data is to be added or removed, a new seed must be generated with mix ecto.gen.seed or use perennial_seed/1.

A seed must be encased in a function named planter to be run. If multiple seeds are defined in a planter they will run but will not handle errors/transactionality correctly. This is strongly discouraged

Example

import Botanist

alias MyApp.Repo
alias MyApp.User

def planter do
  seed do
    Repo.insert(%User{email: "email@gmail.com", name: "John Smith"})
  end
end

If at any point an error is thrown or raised or the seed returns {:error, error_msg}, the seed will be listed as failed. In order for the seed to take root, it will need to be corrected and reran.

As the seed takes place in a transaction, it is not possible for a seed to run partially.