[DB] Creating new databases #141
Labels
No labels
_CRITICAL_
API
app
backEnd
Blocked, waiting for further changes
bug
cleanup
close
design
duplicate
enhancement
feature request
frontEnd
help wanted
invalid
low priority
needs input
needs review
project documentation
question
research
reviewed
script
security
SQL
style
testing
topLevel
wontfix
No milestone
No project
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Andras/BoundlessFlowCampus2K#141
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We need to figure out how to create new databases and run them through docker.
Currently the compose file uses a standard postgres image, the documentation can be found here https://hub.docker.com/_/postgres .
So, we have two ways of creating and using databases through docker.
Create new databases on the same container
The first time a postgres container is started, every .sql and .sh file in the directory /docker-entrypoint-initdb.d is run. So you just link a .sql file to that directory (add the link to the postgres service volumes in compose.yaml) with "CREATE DATABASE ...;" for each additional database you want to create.
NOTE: the database "sensors" is still created. Also, you need to remove the old volumes (eg. docker compose down -v) for it to run the files in /docker-entrypoint-initdb.d every time a new database is added.
All databases created this way share the same password and ports.
Create a new container for each database
It is also possible to just add another service to the compose.yaml file that also uses the postgres image. Then the port and name have to be different from the first database, and you can also set a different password.
Using different containers for the databases has a larger overhead, but the advantage is that the databases are more independent. Eg. Having all databases in the same container is a single point of failure. Using different containers, the one database can crash while the others continue running.
Good explanation and correct understanding of both approches.
The use of docker-entrypoint-initdb.d is accurately described, especially that scripts only run on first initialization (when no volume exists), which is important.
The comparison between single container vs multiple containers is also clear and highlights trade-offs like simplicity vs isolation.
Also, note that the default database,e.g. "sensors" depends on the current configuration, not Postgres itself. Overall, this is correct and useful.
I’ve tested it now and it seems to work as intended. PostgreSQL starts correctly and both sensors and sensors_test are present, so from my side it looks ready to be merged.
Review
I have created test databases using both methods and it works well.
If this is supose to show what methods are avalible it's good, a google search with the information avalible in the document can lead you to the solution.
But if it's a guide to impliment these some things can be added to help with setting up the databases.
on way 1. the first time a new db is setup some files needs to be creaeted, after the first time its done its just as you have described.
on way 2. I beleve the diffrent dbs need sepperate volumes and then you also have to add at the bottom of the .yaml files the new volume.
I think this can be put in the wiki as is and if a guide should be made it can be a new issue to expand on this.
I think if we are to put this in the wiki, we should choose one "standard" way that we use to add new databases (team leader's choice). In my uneducated opinion, we should go with option 1.
We already have a branch that implements option 1 (adds the necessary files) and a test database, so the wiki would only have to include an explanation of how it works and how to add new databases.
I agree with option 1, after the files are created its easy to make new dbs, and i dont see a reason why we need diffrent passwords for the dbs. But checking with the teamleader can be a good idea.
I believe it might be good to document both, as having databases that don't exist in the same volume could be useful. Although it isn't necessary right now, having different ports and passwords for databases will definitely be required later on.
Will close this issue.