ppff
Hello there,
I’m trying to define a mix alias to clear, recreate and seed my database before starting the phoenix server.
Here is my alias config:
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/customer_repo/seeds.exs --no-halt"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
seededserver: ["ecto.reset", "phx.server"],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
When I run mix seededserver, everything goes very well up to the seeds. Once they are executed, nothing happens. It’s like phx.server isn’t called. However, elixir doesn’t quit either. The VM just hangs on. Emptying my seeds script doesn’t change anything. If I remove phx.server, elixir quits normally, and if I remove the call to the seeds script, phx.server runs normally.
I’ve tried many different things, I’ve read the docs, but I can’t wrap my head around this. I feel like I can’t see the elephant in the room, and I don’t know why.
Thanks for your help, strangers.
EDIT: to be clear, I would just like to understand technically why phx.server can’t be run after the seeds script.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Hi and welcome,
I am not sure why You would want to link the reset of your database with the start of your server.
I also prefer to start my dev server with…
… because it allows direct interaction with console.
Anyway, I am not sure what You expect, but when You run mix phx.server, the shell is blocked. until You kill the server.
wolfiton
Hi,
Do you want too reseed the test database at each restart? or what are you trying to reset?
ppff
My
seededserveralias is for a special case where I test my dev config in a clean environment using docker. I fire up my code in a container along with postgres and other services and want to have an environment ready (which means: with seeds) for manual tests.I really don’t see why this wouldn’t work.
wolfiton
I don’t know if you heard but there is a book written by the authors of phoenix and elixir where they explain the whole framework and build an app with tests seeds and so on. Also they explain that the seed happens once you don’t need to reset anything only if you wnat to add new data. But if you have a unique constraint in place it shouldn’t be a problem.
The book is programming phoenix 1.4, you can’t also get a discount using the forum partnership with praprog.
ppff
Thanks for the tip, I’ll sure check this book out!
However, my question is still unanswered. Be it a good or bad idea, I don’t see why my config wouldn’t work.
wolfiton
OK i will give you my point of view:
Why would I reset my database at each server startup when can i have my data there to use it right away when I don’t have any new data to add to the db?
So I have my article data for example I can use it
and then need to shutdown the server to add a new feature, but this feature doesn’t affect my data that i need so why would I reset my database, when i turn the server back again. if i already have my data there?
So it’s is pointless to reset your data at each server restart and costly that is the bottom line.
cnck1387
If you want to go fully clean on every start up you can remove your PostgreSQL volume from Docker so that when the container dies, all of your data is gone and the next time you start things up it’ll be a 100% fresh DB.
If you want volumes most of the time you can also run
docker-compose down -vto wipe your DB, then the next time youdocker-compose up, it’s a fresh slate. This is something I do a lot in my own projects when I’m generating fake data (and I’m actively testing the code to generate that fake data).Then the problem reduces down to just seeding your DB on every start up.
ppff
Thanks but that’s not helping. I’m just looking for someone who understands precisely how aliases and mix work and can explain why this config is broken.
ppff
That’s what I do indeed. The problem is starting phx.server after the seeds. Although it might not be a recommended or usual practice, I would just like to understand why it doesn’t work.
cnck1387
You can always reverse the order. Drop the alias idea, and start Phoenix normally. Then create a Docker ENTRYPOINT script to run your seed file. That would execute every time the container starts.