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

fix(models): add missing foreign key to workflow_uuid of Job (#214) #214

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

mdonadoni
Copy link
Member

Closes #210

Depends on #213

Copy link

codecov bot commented Nov 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.31%. Comparing base (67a7254) to head (5b41246).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #214      +/-   ##
==========================================
+ Coverage   73.28%   73.31%   +0.02%     
==========================================
  Files           7        7              
  Lines         917      918       +1     
==========================================
+ Hits          672      673       +1     
  Misses        245      245              
Files Coverage Δ
reana_db/models.py 90.35% <100.00%> (+0.01%) ⬆️

@mdonadoni
Copy link
Member Author

mdonadoni commented Nov 27, 2023

This PR does not handle the cleaning of the database to make sure that all the values in workflow_uuid are valid non-null foreign keys.

Should the cleanup be performed in the migration, by deleting the related records? Otherwise, we have to instruct the administrator to perform the cleanup manually

UPDATE: the alembic migration now also deletes the jobs referring to non-existing workflows

@mdonadoni mdonadoni marked this pull request as draft November 29, 2023 14:28
mdonadoni added a commit to mdonadoni/reana-db that referenced this pull request May 31, 2024
@mdonadoni mdonadoni changed the title models: add missing foreign key to workflow_uuid of Job fix(models): add missing foreign key to workflow_uuid of Job (#214) May 31, 2024
Comment on lines 25 to 54
# 1. delete jobs which refer to non-existing workflows
op.execute(
job_table.delete().where(
job_table.c.workflow_uuid.notin_(sa.select([workflow_table.c.id_]))
)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

⚠️ Jobs that are not part of an existing workflows are deleted!

@mdonadoni mdonadoni marked this pull request as ready for review May 31, 2024 12:25
@mdonadoni
Copy link
Member Author

mdonadoni commented May 31, 2024

TODO: test this on DEV/QA/PROD clone

@mdonadoni
Copy link
Member Author

This was tested on a clone of DEV

"ALTER CONSTRAINT fk_job_cache_job_id_job DEFERRABLE"
)
)
op.execute(sa.text("SET CONSTRAINTS __reana.fk_job_cache_job_id_job DEFERRED"))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, shall we do a check first whether there would be any rows deleted by this upgrade, and if not then we are good, and if yes shall we warn the user beforehand about the deletion in order to ask for the permission to do so?

(FWIW I think it is perfectly OK, practically, to also remove the rows in this hard-way, since if a job is not attached to a workflow, then chances are it is not exposed to users at all, and so it's ready for the deletion. I'm just wondering, theoretically, whether this isn't a good occasion to introduce an interactive please-confirm-action upgrade technique for DB recipes. Could serve as a nice example for the future?)

@tiborsimko tiborsimko merged commit 5b41246 into reanahub:master Aug 23, 2024
15 checks passed
@mdonadoni mdonadoni deleted the foreign-key branch August 29, 2024 10:20
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.

models: missing foreign key in Job table
2 participants