botanist v0.1.4 Botanist View Source

Botanist is a seeding library which uses Ecto. Its intended purpose is for seeding 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 in terms of atomicity and robustness but will run every time mix ecto.seed is called rather than once

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 in terms of atomicity and robustness but will run every time mix ecto.seed is called rather than once.

Unlike seed/1, multiple perennial_seed can be planted in a single planter function.

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. Only a single seed can fit into a planter.

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.