Database library for use by services
- You can start a database server and a pgAdmin with the following command. It should be run fron the root directory of this repository
docker-compose up
After you see this output, everything should be up and running:
- Login into the pgAdmin: Now you can login into pgAdmin when you open the URL http://localhost:8011 in your browser.
The username is backend@backend.xyz
and the password is backend
.
After login you should be in the pgAdmin view.
- Next right click on "Servers" and select Register > Server...
- After that a pop window should open. Setup the connection to the database server.
Give it a name.
Next fill out the Connection details. The username password for the db server is "backendgang".
Finally select save.
Now a new connection should appear.
- You can inspect the database tables, by inspecting until schema.
- If you want to display data inside a table you can right click on a table, then select "View/Edit Data" > "First 100 Rows"
Finally you should see the data.
-
Change directory to the examples directory
-
Create a virtualenv in the exammples folder:
- Activate the virtualenv
- Install the requirements
pip install -r requirements.txt
- Now you can run any script inside the examples directory.
You can install the library by running the following pip command:
pip install --upgrade --force-reinstall git+https://github.com/Projekt-DataScience/backend-db-lib@main#egg=backend_db_lib
You can also add the following line to your requirements.txt:
git+https://github.com/Projekt-DataScience/backend-db-lib@main#egg=backend_db_lib
KEEP IN MIND THAT YOU WILL LOOSE ALL YOUR DATA IN THE DATABASE DURING THIS PROCESS
When this repository changes, you can reinstall it, by following the following steps.
- The changes should already be pushed to this main branch
- Stop you database server
- Navigate to the repository, where you have installed this library and want to update. In this case I want to update it for backend-audit. Activate you virtualenv if not done yet
- Reinstall the library with the following pip command. This command will uninstall and install the backend_db_lib library.
pip install --upgrade --force-reinstall git+https://github.com/Projekt-DataScience/backend-db-lib@main#egg=backend_db_lib
You can also reinstall all packages, if you have a requirements.txt file, with the following command:
pip install --upgrade --force-reinstall -r /app/requirements.txt
- Delete docker containers of your repository. The following command will delete all unused containers, so be careful
docker container prune
If you just want to delete specific containers, then run the following command:
docker container rm [CONTAINER_IDS]
- Delete the volume of your container. You can do that with the following command. But be careful that command deletes all unused volumes.
docker volume prune
If you want to delete specific volumes, then use the following command:
docker volume rm [OPTIONS] VOLUME [VOLUME...]
- Next you can start the database container again. Make sure, you are in the right directory. For me it is
~/Projects/backend-db-lib
docker-compose up
Wait until the database server and Admin UI are fully up.
- Next you can build your containers again. Make sure you are in the right directory, for me it is
~/Projects/backend-audit
:
docker-compose up --build
You should see, that the backend_db_lib is installed again.
Finally, you container should be up and running.
- Next go to the examples directory inside the backend-db-lib repository. There should be a virtualenv, which you should activate.
- Inside this virtualenv, you should also reinstall the library.
pip install --upgrade --force-reinstall git+https://github.com/Projekt-DataScience/backend-db-lib@main#egg=backend_db_lib
- Now run the create_schema.py scripts, to create the schema and add some dummy data.
python create_schema.py
- After that the schema, should be created, with the changes, that you have pushed. You can inspect that in pgAdmin.
In this case, I have added the class "LPAAuditDuration". I can see, that the table was added successfully and that it contains the right columns.
I can also import the class in the code without problems.