Anonyymioodi - test database setup
This folder contains a guide and scripts to modify or create anonymous database images for Oodikone, mainly used for testing.
The quick guide should be enough for most purposes: updating schema, data, or the PostgreSQL version. If you need to generate completely new sis-importer-db and sis-db images (which shouldn't happen too often), follow the instructions in the section Generate new sis-importer-db and sis-db completely from scratch.
Quick guide to updating a test database
-
Ensure you have the latest test-db. Just pulling images might not replace your existing volume, so you may need to remove it manually. This command might work:
docker volume rm oodikone-sis-db-data(replaceoodikone-sis-db-datawith the correct volume name). The new image, including data, should be pulled the next time you launch Oodikone normally. -
Do your dev work as usual with the test database, for example, using
npm run both. Edit data as needed, (for example, run the updater via the frontend), and then run tests to see if they pass (follow the instructions in the README to run the tests more quickly). -
If you're updating
sis-db:- Modify the scheduler limit in config.js by setting
module.exports.DEV_SCHEDULE_COUNT = null. - Follow the
sis-updater-workerlogs to ensure everything is running smoothly (docker logs --follow oodikone-sis-updater-worker).
- Modify the scheduler limit in config.js by setting
-
When you're satisfied with the database, create a dump:
- Use the command:
docker exec -i <dbname> pg_dump -Fc -U postgres <dbname> > anonyymioodi/<dbname>.sqz.
- Use the command:
-
Shut down the environment with
npm run docker:down. -
Navigate to this folder:
cd anonyymioodi. -
If you need to update the PostgreSQL version, do it now by changing the version in this directory's
docker-compose.yml. The version should match the one used on the server to avoid compatibility issues. -
Create a new container from the dump:
./create_container_from_dump.sh <dbname>. -
Commit and push it to the Toska registry:
./commit_and_push_to_toska_hub.sh <dbname>. -
Bring down the environment with
docker compose down.
Generate new sis-importer-db and sis-db completely from scratch
Caution
The more the data in
sis-importer-dbandsis-dbchanges, the more tests might break. Because of this, it's highly recommended to make as few changes as possible (for example, avoid changing the degree programs whose students are used in the test data).If you only need to make small changes, follow the quick guide above.
Sis-importer-db
-
To generate a sample dump from test Sisu data, follow the instructions at importer-db-staging-sampletaker inside the
sis-importerrepo. -
Copy
sis-importer-db.sqzinto this folder. -
Run the following commands (in this folder) to create a new image from the dump and push it to the Toska registry:
./create_container_from_dump.sh sis-importer-db ./commit_and_push_to_toska_hub.sh sis-importer-db docker compose down
Sis-db
-
To ensure the newest
sis-importer-dbimage is used:- Delete all
sis-importer-dbimages you have locally (list images withdocker images, delete withdocker rmi <image ID>). - Also, delete the old
sis-importer-dbvolume (docker volume rm sis-importer-db-data).
- Delete all
-
Start Oodikone and Updater with
npm run both(this will pull the newestsis-importer-dbimage you just pushed in the previous step). -
Truncate all tables in
sis-dbexcept formigrationsandsemesters(the easiest way is to use Adminer). -
Modify the scheduler limit in config.js by setting
module.exports.DEV_SCHEDULE_COUNT = null. -
Navigate to http://localhost:3000/updater and click the three buttons (Update meta, Update students, Update curriculums) one by one. This will populate
sis-dbwith data from the newsis-importer-db. You might want to do each update a couple of times, as the database tables affect each other, and not all necessary data might be generated on the first try. -
Follow the
sis-updater-workerlogs to ensure everything is running smoothly (docker logs --follow oodikone-sis-updater-worker). If you see any errors, try clicking the buttons again. -
Run all the tests to ensure everything is working as expected (follow the instructions in the README to run the tests more quickly). If any tests fail, update the test files accordingly.