tethysplatform / tethys

The Tethys Platform main Django website project repository.
http://tethysplatform.org/
BSD 2-Clause "Simplified" License
92 stars 49 forks source link

Check for existing database before trying to create it #896

Open sdc50 opened 1 year ago

sdc50 commented 1 year ago

When running the Docker build the database creation step will fail if the docker is connecting to an existing database.

We could change the unless argument in the salt script so that it checks for the existence of the database before trying to create it.

The easiest place to check for the existence of a database would be in the db_commands module with a command like:

psql -lqtp <DB_PORT> -U postgres | awk '{print $1}' | grep -qw <DB_NAME>

We could add an additional sub-command to the tethys db commands that checks for the existence of a db, and the unless argument in the salt script could call that command.

Alternatively, we could check for the existence of the db inside the create_db_user function of the db_commands, and not try to create the db (and return an error) if the db already exists.

swainn commented 1 year ago

https://github.com/tethysplatform/tethys/blob/f8fd9883ced2ca6212a925a4f102a44cf9695afb/docker/salt/tethyscore.sls#L139-L148