Drill

Seed data handling for Elixir

Drill is an elixir seeder library inspired by Seed Fu and Phinx.

Usage

  1. Create your seeder modules. The directory where the seeder modules are located does not matter as long as it has use Drill, ....

In my_app/lib/seeds/user.ex:

defmodule MyApp.Seeds.User do
  use Drill, key: :users, source: MyApp.Accounts.User

  def run(_context) do
    [
      %{
        email: "user1@example.com",
        first_name: "John",
        last_name: "Smith"
      },
      ...
    ]
  end
end

In my_app/lib/seeds/post.ex:

defmodule MyApp.Seeds.Post do
  use Drill, key: :posts, source: MyApp.Blogs.Post

  def deps do
    [MyApp.Seeds.User]
  end

  def run(%Drill.Context{seeds: %{users: [user1, user2, user3 | _]}}) do
    [
      %{
        content: Lorem.paragraph(),
        user_id: user1.id
      },
      ...
    ]
  end
end
  1. Configure drill by adding the name of your application. This will let drill know which application contains the seeder modules. In my_app/config/config.exs:
config :drill, :otp_app, :my_app
  1. Run mix drill --r MyApp.Repo in the terminal with your project root as the current working directory

Installation

Drill is available on Hex.

To add it to a mix project, just add a line like this in your deps function in mix.exs:

def deps do
  [
    {:drill, "~> 0.1", only: [:dev, :test]},
  ]
end

use Drill options

Callbacks

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/drill.