Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Languages sync patch via command (docker issues #78) #1693

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Victorivus
Copy link

@Victorivus Victorivus commented Jun 10, 2024

Proposed Changes

Please check that the PR fulfills these requirements

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

Other questions

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

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

@Victorivus
Copy link
Author

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
Copy link
Author

Victorivus commented Jun 13, 2024

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
Copy link
Author

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

@rolandgeider
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants