-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Seeding scripts #2330
Seeding scripts #2330
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecate_models
method doesn't work for me if I add names to DEPRECATED_X
variables - suggestions should fix it. Looks good otherwise.
Does the seeding get run automatically during the deployment process?
amy/workshops/utils/seeding.py
Outdated
_info(f"Start of {class_name} deprecation.") | ||
|
||
for i, model_id in enumerate(model_id_list): | ||
if not model_class._default_manager.filter({lookup_field: model_id}).exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not model_class._default_manager.filter({lookup_field: model_id}).exists(): | |
if not model_class._default_manager.filter(**{lookup_field: model_id}).exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Thanks, fixing now.
amy/workshops/utils/seeding.py
Outdated
continue | ||
|
||
_info(f"{i} {class_name} <{model_id}> exists, removing.") | ||
model_class._default_manager.filter({lookup_field: model_id}).delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model_class._default_manager.filter({lookup_field: model_id}).delete() | |
model_class._default_manager.filter(**{lookup_field: model_id}).delete() |
If we wanted to update an existing entry (e.g. change the text of an email template), how would we do that with this setup? |
Yes, it's part of Dockerfile
That's a great question. It should be agreed with product users that they accept potential overwrite of their changes. In this case, I assumed that no changes to existing email templates should be lost as a result of seeding. I'm using a very similar setup to update entries during seeding, the change lies in these lines ( if model_class._default_manager.filter(**{lookup_field: model_id}).exists():
_info(f"{i} {class_name} <{model_id}> already exists, skipping.")
continue When existing object is found, the code makes an update of specific fields from model definition instead of skipping. |
This fixes #2239 by providing an alternative to fixtures from Django.
Seeding scripts give more control to the developer. This way it was possible to implement a check before given entity gets created.