Skip to content

Instantly share code, notes, and snippets.

@luc-tielen
Created October 11, 2017 08:41
Show Gist options
  • Save luc-tielen/53e81b1c812ab362634cdb583672f529 to your computer and use it in GitHub Desktop.
Save luc-tielen/53e81b1c812ab362634cdb583672f529 to your computer and use it in GitHub Desktop.
Seed works fine locally, but not in docker container?
# NOTE: using alpine-elixir-phoenix docker image
DOCKER_ID=$(shell docker ps -aqf "name=webserver")
.PHONY: run
run:
docker-compose up
.PHONY: init_db
init_db:
docker exec -ti ${DOCKER_ID} mix do ecto.create, ecto.migrate
docker exec -ti ${DOCKER_ID} mix run priv/repo/seeds.exs
# File stored in priv/repo/seeds.exs
alias QuoteApp.Quote.QuoteRecord
alias QuoteApp.Repo
Repo.delete_all(QuoteRecord)
[
{"Philip Greenspun", "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."},
{"Edsger Dijkstra", "Simplicity and elegance are unpopular because they require hard work and discipline to achieve and education to be appreciated."},
{"Brian Kernighan", "Controlling complexity is the essence of computer programming."},
{"Linus Torvalds", "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."},
{"Donald Knuth", "Everyday life is like programming, I guess. If you love something you can put beauty into it."},
{"John Carmack", "Programming is not a zero-sum game. Teaching something to a fellow programmer doesn't take it away from you. I'm happy to share what I can, because I'm in it for the love of programming."},
{"Thomas C. Gale", "Good design adds value faster than it adds cost."
},
{"Martin Golding", "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."},
{"Brian W. Kernighan", "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."}
]
|> Enum.map(fn {name, text} ->
Repo.insert!(%QuoteRecord{name: name, text: text})
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment