wger icon indicating copy to clipboard operation
wger copied to clipboard

Languages sync patch via command (docker issues #78)

Open Victorivus opened this issue 1 year ago • 4 comments

Proposed Changes

  • I added a command to core management sync_core_languages which fixes the error of languages having different IDs if we deleted some and made an exercise sync after (https://github.com/wger-project/docker/issues/78)
  • Temporal patch while https://github.com/wger-project/wger/issues/1667 gets developped

Please check that the PR fulfills these requirements

  • [X] Tests for the changes have been added (for bug fixes / features)
  • [X] Added yourself to AUTHORS.rst

Other questions

If you encounter the languages problem (e.g. https://github.com/wger-project/docker/issues/78), just run:

  • manage.py sync_core_languages or
  • docker compose exec web python3 manage.py sync_core_languages

Victorivus avatar Jun 10 '24 08:06 Victorivus

I didn't manage to get the test running locally if someone can help.

The command itself works as expected:

We delete language 22 (Croatian) and sync exercises, so it creates it with last id +1 (45 here) Capture d’écran du 2024-06-08 22-06-13

The sync fails: Capture d’écran du 2024-06-08 22-33-07

After running this new command sync_core_languages: Croatian gets back to 22 and the sync is performed without problems Capture d’écran du 2024-06-08 22-57-27

Victorivus avatar Jun 10 '24 09:06 Victorivus

Tests weren't passing because it was Postgre specific. Now they do work (https://github.com/Victorivus/wger/pull/1/checks).

Changes made:

  • Removed PostgreSQL-specific commands: Removed SET session_replication_role = 'replica'; and SET session_replication_role = 'origin';.
  • Temporary table creation: Used CREATE TEMPORARY TABLE and handled the case if it's not supported by falling back to CREATE TEMP TABLE.
  • Django ORM: Used Django ORM for updating or creating records in the core_language table.
  • Database compatibility: Made sure the SQL used for inserting and updating records is compatible with both PostgreSQL and SQLite.

Test in "production" was done as so:

  1. Run docker exec -ti wger_db psql -U wger
  2. # DELETE FROM exercises_exercise WHERE language_id =22; DELETE from core_language where id=22;
  3. The command sync-exercises (docker compose exec web python3 manage.py sync-exercises) will now throw errors and not work, it will create languages wth different ids than original ones.
  4. Run this PR's command sync_core_languages (docker compose exec web python3 manage.py sync_core_languages)
  5. Now sync-exercises (docker compose exec web python3 manage.py sync-exercises) will work properly as expected.

Victorivus avatar Jun 13 '24 17:06 Victorivus

@rolandgeider just to let you know that I fixed the test pipeline if you want to rerun it

Victorivus avatar Jun 19 '24 15:06 Victorivus

haven't forgotten you, will take a look this weekend

rolandgeider avatar Jun 26 '24 15:06 rolandgeider