Database Management - BP2022-AP1/bp2022-ap1 GitHub Wiki
By running bin/db you can manage the dev database and the test database.
Both databases run inside a docker container. Therefore, you have to be part of the docker group on linux os. To start one of these containers run docker compose up postgresql for the dev database or docker compose up postgresql-test for the test database. The latter should not be necessary because executing poe test will automatically run the test database, drop and recreate all its tables, run the tests and then stop the database container again.
The dev databases will be available at localhost:5432 and test at localhost:5430.
You can interact with the database content with the poe db and poe db-test command. The next paragraphs will discuss some commands with poe db.
If you have started a database for the first time, you need to create its tables. By running poe db create the tables of the currently running database will be created.
You can drop all tables of the existing database by executing poe db drop.
By running poe db recreate all tables of the currently running database will be dropped and then created again.
To create a migration for the currently running database execute poe db migration create <NAME> where <NAME> is an arbitrary name given by you.
You can find the migration file in db/local/migrations. You need to implement the changes to the database there (added models, added rows, removed rows, ...). Inside the file are helpful comments.
Afterwards you can run the migration with poe db migration run <NAME>.
By running poe db migration run ALL you can run all unapplied migrations.
You can rollback the last migration with poe db rollback.
We have different identifier in order to reference and identify the domain-objects correctly. These are documented below.
Object.property |
datatype | notes | Questions? Ask ... |
|---|---|---|---|
| Train.identifier | str | Procedurally generated from Schedule-ID, spawn-tick and train type with following format: <SCHEDULE_ID>_<TICK>_<TRAIN_TYPE>
|
@CR1337 |
| Track.identifier | str / uuid | Generated by yaramo / read from PlanPro file | @Saturnhafen |
| Signal.identifier | str / uuid | Generated by yaramo / read from PlanPro file | @Saturnhafen |
| Platform.identifier | str | Generated by hand | @Saturnhafen |
| Switch.identifier | str / uuid | Generated by yaramo / read from PlanPro file | @Saturnhafen |
| Schedule.id | uuid | Generated by the api (the database contains only a ScheduleConfiguration with the same id) |
@CR1337 |
| Spawner.id | uuid | Generated by the api (the database contains only a SpawnerConfiguration with the same id) |
@CR1337 |
| *Fault.configuration.id | uuid | Generated by the api (the database only contains the configuration) | @instant-sky |