Skip to content

Projekt-DataScience/backend-db-lib

Repository files navigation

backend-db-lib

Database library for use by services

Database Schema

Link to Schema

Setup DB

  1. 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

2022-12-10-11-22.png

After you see this output, everything should be up and running:

2022-12-10-11-23.png

  1. Login into the pgAdmin: Now you can login into pgAdmin when you open the URL http://localhost:8011 in your browser.

2022-12-10-11-24.png

The username is backend@backend.xyz and the password is backend.

After login you should be in the pgAdmin view.

image

  1. Next right click on "Servers" and select Register > Server...

image

  1. After that a pop window should open. Setup the connection to the database server.

Give it a name.

image

Next fill out the Connection details. The username password for the db server is "backendgang".

image

Finally select save.

image

Now a new connection should appear.

image

  1. You can inspect the database tables, by inspecting until schema.

image

  1. If you want to display data inside a table you can right click on a table, then select "View/Edit Data" > "First 100 Rows"

image

Finally you should see the data.

image

How to run the examples

  1. Change directory to the examples directory

  2. Create a virtualenv in the exammples folder:

image

  1. Activate the virtualenv

image

  1. Install the requirements
pip install -r requirements.txt

image

  1. Now you can run any script inside the examples directory.

How to install library

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

2022-12-10-11-21.png

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

How to reinstall

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.

  1. The changes should already be pushed to this main branch

2022-12-10-10-55.png

  1. Stop you database server

2022-12-10-10-54.png

  1. 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

2022-12-10-10-57.png

  1. 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

2022-12-10-10-58.png

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
  1. Delete docker containers of your repository. The following command will delete all unused containers, so be careful
docker container prune

2022-12-10-11-03.png

If you just want to delete specific containers, then run the following command:

docker container rm [CONTAINER_IDS]
  1. 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

2022-12-10-11-05.png

If you want to delete specific volumes, then use the following command:

docker volume rm [OPTIONS] VOLUME [VOLUME...]
  1. 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.

2022-12-10-11-09.png

2022-12-10-11-08.png

  1. 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.

2022-12-10-11-11.png

2022-12-10-11-12.png

Finally, you container should be up and running.

2022-12-10-11-13.png

  1. Next go to the examples directory inside the backend-db-lib repository. There should be a virtualenv, which you should activate.

2022-12-10-11-15.png

  1. 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

2022-12-10-11-16.png

  1. Now run the create_schema.py scripts, to create the schema and add some dummy data.
python create_schema.py

2022-12-10-11-17.png

  1. 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.

image

I can also import the class in the code without problems.

image

About

Database library for use by services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •