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

Candidatures : Utiliser un autre domaine pour le lien vers le CV [GEN-1628] #4053

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import time

from django.db import migrations
from django.db.models import Value
from django.db.models.functions import Concat, Substr


def forwards(apps, editor):
print()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor Author

@francoisfreitag francoisfreitag May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C’est exprès, c’est pour revenir à la ligne avant d’écrire.
Django a son moyen d’afficher les migations :

Apply migrations
  0003_workaround_clever_dangerous_domain_ms... 

Sans \n après les points de suspension.
Sans le print() :

  0003_workaround_clever_dangerous_domain_ms... Updated 20000 job applications, migration duration XXXs
Updated 40000 job applications, migration duration XXXs
OK

Avec le print() :

  0003_workaround_clever_dangerous_domain_ms... 
Updated 20000 job applications, migration duration XXXs
Updated 40000 job applications, migration duration XXXs
OK

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaah ! Merci de l'explication. :)

JobApplication = apps.get_model("job_applications", "JobApplication")
total = 0
start = time.perf_counter()
updated = True
while updated:
slice = JobApplication.objects.filter(
resume_link__startswith="https://cellar-c2.services.clever-cloud.com/",
)[:20_000]
updated = JobApplication.objects.filter(pk__in=slice).update(
resume_link=Concat(
Value("https://par.cellar.clever-cloud.com"),
Substr("resume_link", len("https://cellar-c2.services.clever-cloud.com") + 1),
)
)
total += updated
if updated:
print(f"Updated {total} job applications, migration duration {time.perf_counter() - start:.2f}s")
time.sleep(1)


class Migration(migrations.Migration):
"""
The domain cellar-c2.services.clever-cloud.com has been flagged as dangerous by Microsoft.

Apply Clever workaround to use another domain.
"""

atomic = False

dependencies = [
("job_applications", "0002_jobapplication_refusal_reason_shared_with_job_seeker"),
]

operations = [migrations.RunPython(forwards, elidable=True)]