Drill

Seed data handling for Elixir

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

Documentation

Official documentation on hexdocs

Usage

  1. Create your seeder modules. The directory where the seeder modules should be located is described on mix drill documentation.

In my_app/priv/repo/seeds/user.exs:

defmodule MyApp.Seeds.User do
use Drill, key: :users, source: MyApp.Accounts.User
def factory do
%{
first_name: Person.first_name(),
last_name: Person.last_name()
}
end
def run(_context) do
[
seed(email: "email1@example.com"),
seed(email: "email2@example.com"),
seed(email: "email3@example.com")
]
end
end

In my_app/priv/repo/seeds/post.exs:

defmodule MyApp.Seeds.Post do
use Drill, key: :posts, source: MyApp.Blogs.Post
alias Faker.Lorem
def deps do
[MyApp.Seeds.User]
end
def factory do
%{content: Lorem.paragraph()}
end
def run(%Drill.Context{seeds: %{users: [user1, user2, user3 | _]}}) do
[
seed(user_id: user1.id),
seed(user_id: user2.id),
seed(user_id: user3.id)
]
end
end
  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, "~> 1.0", only: [:dev, :test]},
]
end

Configurations

Timeout

Default timeout is 600 seconds or 10 minutes. You may configure the task timeout in your config.exs file. For example: config :drill, :timeout, 10_000

use Drill options

Callbacks

Caveat

Can only be used on Postgres database for now

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