An Elixir library that provides a simple DSL for seeding databases through Ecto.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.gitignore
README.md
mix.exs
mix.lock

README.md

Exseed

An Elixir library that provides a simple DSL for seeding databases through Ecto.

Inspired largely by seed-fu.

Installation

In your project's mix.exs add the following:

    defp deps do
      {:exseed, "~> 0.0.3"}
    end

and then run mix deps.get.

Setup

In config/config.exs add:

    config :exseed, :repo, YourApplication.Repo

Usage

Exseed provides a seed macro which expects an Ecto model and a block. Inside the block the fields on your model will be available as functions which will set the value for the field for that record.

By default Exseed will look in your project's priv/repo/seeds/ directory for seed files to load. Let's say you have a model named Post, you could put the following in priv/repo/seeds/posts.exs:

    import Exseed

    seed YourApplication.Post do
      id 1

      title "First Post!"

      body "Hello, world!"
    end

    seed YourApplication.Post do
      id 2

      title "Second Post"

      {{year, month, day}, {hour, minute, second}} = :calendar.universal_time()

      body "This entry was seeded at #{year}-#{month}-#{day} #{hour}:#{minute}:#{second}."
    end