Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://github.com/CircleCI-Public/circleci-demo-elixir-phoenix
version: 2.0
jobs:
build:
working_directory: ~/exseed
docker:
- image: elixir:1.5.1
environment:
- MIX_ENV=test
- image: postgres:9.6.3
environment:
- POSTGRES_USER=postgres
steps:
- checkout
- run: echo "Yes" | mix local.hex
- run: echo "Yes" | mix local.rebar
- run: mix deps.get
- run: mix test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ An Elixir library that provides a simple DSL for seeding databases through Ecto.

Inspired largely by [seed-fu](https://github.com/mbleigh/seed-fu).

[![CircleCI](https://circleci.com/gh/seaneshbaugh/exseed/tree/master.svg?style=svg)](https://circleci.com/gh/seaneshbaugh/exseed/tree/master)

## Installation

In your project's `mix.exs` add the following:
Expand Down
26 changes: 14 additions & 12 deletions lib/mix/tasks/exseed.seed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@ defmodule Mix.Tasks.Exseed.Seed do
import Mix.Ecto

def run(args) do
repo = parse_repo(args)
repos = parse_repo(args)

ensure_repo(repo, [])
Enum.each repos, fn repo ->
ensure_repo(repo, [])

Mix.Task.run "app.start", args
Mix.Task.run "app.start", args

{opts, _, _} = OptionParser.parse args, switches: [quiet: :boolean, path: :string]
{opts, _, _} = OptionParser.parse args, switches: [quiet: :boolean, path: :string]

seed_path = opts[:path] || "priv/repo/seeds/"
seed_path = opts[:path] || "priv/repo/seeds/"

unless File.exists?(seed_path) do
raise File.Error, reason: :enoent, action: "find", path: seed_path
end
unless File.exists?(seed_path) do
raise File.Error, reason: :enoent, action: "find", path: seed_path
end

{:ok, seed_files} = File.ls(seed_path)
{:ok, seed_files} = File.ls(seed_path)

seed_files |> Enum.each(&(Code.load_file(Path.join(seed_path, &1))))
seed_files |> Enum.each(&(Code.load_file(Path.join(seed_path, &1))))

unless opts[:quiet] do
Mix.shell.info "The database for #{inspect repo} has been seeded."
unless opts[:quiet] do
Mix.shell.info "The database for #{inspect repo} has been seeded."
end
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Exseed.Mixfile do
defp deps do
[
{ :earmark, "~> 0.2", only: :dev },
{ :ecto, ">= 1.0.0" },
{ :ecto, ">= 1.1.0" },
{ :ex_doc, "~> 0.11", only: :dev }
]
end
Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/exseed.seed_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ defmodule Mix.Tasks.Exseed.SeedTest do
test "runs the seed task" do
Seed.run ["-r", to_string(TestRepo), "--path", "test/support/seeds"]

assert_received {:mix_shell, :info, ["The database for [Exseed.TestRepo] has been seeded."]}
assert_received {:mix_shell, :info, ["The database for Exseed.TestRepo has been seeded."]}
end
end