You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the package, it's already been really useful.
When we use mix release to deploy to production the resulting package no longer has mix itself available for running tasks, so the example in the README doesn't work if you use releases in production.
defmoduleMyApp.Deployment.SeederdoimportEcto.Migrator,only: [migrations_path: 2,with_repo: 2]@app:my_appdefseed(opts\\[],seeder\\&PhilColumns.Seeder.run/4)doload_app()# set env with current_env/0 overwriting provided argopts=Keyword.put(opts,:env,current_env())opts=Keyword.put(opts,:tags,[])opts=ifopts[:to]||opts[:step]||opts[:all],do: opts,else: Keyword.put(opts,:all,true)opts=ifopts[:log],do: opts,else: Keyword.put(opts,:log,:info)opts=ifopts[:quiet],do: Keyword.put(opts,:log,false),else: optsforrepo<-repos()do{:ok,_,_}=with_repo(repo,&seeder.(&1,migrations_path(&1,"seeds"),:up,opts))endenddefpcurrent_envdo## Add this to config/config.exs:#### config :my_app, env: config_env()Application.fetch_env!(@app,:env)enddefpreposdoApplication.fetch_env!(@app,:ecto_repos)enddefpload_appdoApplication.load(@app)endend
which can be run from the release like this:
bin/my_app eval "MyApp.Deployment.Seeder.seed"
Does this sound like the right approach? If so, would this be a useful addition to the README? Happy to provide a PR if it's like to useful to someone.
The text was updated successfully, but these errors were encountered:
Thanks for the package, it's already been really useful.
When we use
mix release
to deploy to production the resulting package no longer hasmix
itself available for running tasks, so the example in the README doesn't work if you use releases in production.Taking inspiration from the examples in the README and in the
Ecto.Migrator
documentation at https://hexdocs.pm/ecto_sql/Ecto.Migrator.html#module-example-running-migrations-in-a-release I've created a seeder task like this:which can be run from the release like this:
Does this sound like the right approach? If so, would this be a useful addition to the README? Happy to provide a PR if it's like to useful to someone.
The text was updated successfully, but these errors were encountered: