-
Notifications
You must be signed in to change notification settings - Fork 2
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
[CZID-8857] Add ConsensusGenomes to seed script #122
Conversation
18485c2
to
b624e32
Compare
# For each file, find the entity associated with it | ||
# and update the file_id for that entity. | ||
files = session.query(File).all() | ||
for file in files: | ||
if file.entity_id: | ||
entity_field_name = file.entity_field_name | ||
entity = session.query(Entity).filter(Entity.id == file.entity_id).first() | ||
if entity: | ||
entity_name = entity.type | ||
session.execute( | ||
sa.text( | ||
f"""UPDATE {entity_name} SET {entity_field_name}_id = file.id | ||
FROM file WHERE {entity_name}.entity_id = file.entity_id""", | ||
) | ||
) |
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.
Definitely open to suggestions on how to improve this 😓
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.
Looks great!
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.
Looks good, just a question about plural_snake_name
# For each file, find the entity associated with it | ||
# and update the file_id for that entity. | ||
files = session.query(File).all() | ||
for file in files: | ||
if file.entity_id: | ||
entity_field_name = file.entity_field_name | ||
entity = session.query(Entity).filter(Entity.id == file.entity_id).first() | ||
if entity: | ||
entity_name = entity.type | ||
session.execute( | ||
sa.text( | ||
f"""UPDATE {entity_name} SET {entity_field_name}_id = file.id | ||
FROM file WHERE {entity_name}.entity_id = file.entity_id""", | ||
) | ||
) |
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.
Looks great!
@@ -80,11 +80,11 @@ async def load_{{ related_field.related_class.snake_name }}_rows( | |||
dataloader = info.context["sqlalchemy_loader"] | |||
mapper = inspect(db.{{ cls.name }}) | |||
{%- if related_field.multivalued %} |
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.
Can you explain this change? Just curious how it still works for plural entities like this one 😅 🪄
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.
This just pulls the related_field
's name as it's defined in the schema; so for the example you linked, the class is Sample
and the related_field
we're looking at is sequencing_reads
!
I'm making the assumption here that since the field is multivalued
, the name defined in the schema is plural.
Ticket: CZID-8857
types
to use the proper field name when getting the relationship from the mappersqlalchemy.exc.IntegrityError: (psycopg.errors.NotNullViolation) null value in column "file_id" of relation "reference_genome" violates not-null constraint
FileFactory.update_file_ids
so all file columns are populatedExample of querying CG data generated from
![Screenshot 2023-11-16 at 4 30 59 PM](https://private-user-images.githubusercontent.com/53838890/283633017-7f7172e8-b341-4179-b2f9-b816d243d1b9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNjE4NzQsIm5iZiI6MTczOTE2MTU3NCwicGF0aCI6Ii81MzgzODg5MC8yODM2MzMwMTctN2Y3MTcyZTgtYjM0MS00MTc5LWIyZjktYjgxNmQyNDNkMWI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDA0MjYxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ1MGY4N2U4MmViNmU5YTU1MGJmNWE2YzAwMTBlNjMwNTgzMzJiOTA5ZGUwMjVmYWE2NjdjZTg1Y2M4NDg2Y2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.tgcy66MzWWJKJhcZbBYaGJNTllXFkKu4DsvZ-jG6Bzg)
seed.py
: