ppff

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.

Showing Posts 1 to 10

kokolegorille

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…

$ iex -S mix phx.server

… 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

wolfiton

Hi,

Do you want too reseed the test database at each restart? or what are you trying to reset?

ppff

ppff OP

My seededserver alias 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

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

ppff OP

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

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

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 -v to wipe your DB, then the next time you docker-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

ppff OP

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

ppff OP

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

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.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews