wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
13.4k stars 1.18k forks source link

[Managed dev db] Allow automatic and/or manual choosing of another port than 5432 #1049

Open Martinsos opened 1 year ago

Martinsos commented 1 year ago

What we want

Right now, when Wasp runs a managed dev db (e.g. via wasp start db), it will run it on port 5432. If that port is already occupied by some other process, or by another Wasp app, starting the db will fail.

Potential solutions

To solve this, we can do one of two (or both) things:

  1. Offer the user ability to specify on which port should managed dev db start. They could specify it via env var, or maybe via some kind of local settings file (we don't have such file yet though).
  2. Wasp could automatically try different ports until one of them is free. It could start with 5432 and then add +1 to it until port is free, then use that port.

Solution implementation details

There are two parts of Wasp that need to know the port: the part where db is started, and later when Wasp project is generated. The only way to transfer that knowledge is to write it down to disk somehow, temporarily. So when managed dev db starts, Wasp should write down the port that it used to start it, to some local, hidden, non-versioned file, that then other wasp processes (for example if you run wasp start or wasp db migrate-dev) can read and obtain info about the port from it.

So far this was not needed because port was hardcoded to 5432, but for this change we will need this sharing of knowledge.

One thing to keep an eye on is that while we can write that file with info about port once that mangaed dev db stars running, we can't guarantee it will get deleted once managed dev db stops running, so we shouldn't even try to delete it we can just give up on that. That means that when we do read that file, we should not assume that means that managed dev db is running -> it just means that if it is running, it is running with this port. But ok, that makes sense!

As for which file could that be, the one into which we write port into -> hm, not sure, we don't have that kind of file yet actually, it would probably have to be a new file. We could store it into .wasp/ dir.

Martinsos commented 1 year ago

This is related to #730 since they will in big part probably use the same mechanisms.

Martinsos commented 1 week ago

@sodic suggested quick soluiton to just use another port than 5432 so to avoid clash with postgres process users might already have running on their machine.