Created
January 18, 2016 20:13
-
-
Save bratsche/ea3085141b35579f1fd5 to your computer and use it in GitHub Desktop.
Example custom mix task to seed the database using an existing seed file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/mix/tasks/musikr.seed.ex | |
defmodule Mix.Tasks.Musikr.Seed do | |
use Mix.Task | |
@shortdoc "Seeds the database" | |
@moduledoc """ | |
Seed the database using the file 'priv/repo/seeds.exs' | |
""" | |
def run(_args) do | |
Code.eval_file("priv/repo/seeds.exs") | |
end | |
end | |
# priv/repo/seeds.exs | |
instruments = ~w(piano violin viola cello bass horn tuba trombone clarinet flute oboe) | |
for i <- instruments do | |
Musikr.Repo.insert!(%Musikr.Instrument{name: i}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment