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

Add delete cascade on DB models #608

Merged
merged 1 commit into from
Oct 30, 2018
Merged

Add delete cascade on DB models #608

merged 1 commit into from
Oct 30, 2018

Conversation

Zlopez
Copy link
Contributor

@Zlopez Zlopez commented Sep 14, 2018

This should prevent orphaned DB objects.
For example packages without project or distribution.

Fixes #598

@@ -656,7 +658,9 @@ class ProjectVersion(Base):
)
version = sa.Column(sa.String(50), primary_key=True)

project = sa.orm.relation('Project', backref='versions_obj')
project = sa.orm.relation(
Copy link

Choose a reason for hiding this comment

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

Maybe you could use the relationship API here like in here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

relation is the synonym to relationship. See here http://docs.sqlalchemy.org/en/latest/orm/relationship_api.html

Copy link

Choose a reason for hiding this comment

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

So why not keep consistency and use the same name either relation or relationship I think it would make the code easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you can see I used the same method that was already there, but you are right I didn't noticed this.

@@ -679,7 +683,9 @@ class ProjectFlag(Base):
updated_on = sa.Column(sa.DateTime, server_default=sa.func.now(),
onupdate=sa.func.current_timestamp())

project = sa.orm.relation('Project', backref='flags')
project = sa.orm.relation(
Copy link

Choose a reason for hiding this comment

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

Same as above

@codecov-io
Copy link

codecov-io commented Sep 19, 2018

Codecov Report

Merging #608 into master will increase coverage by 0.48%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #608      +/-   ##
==========================================
+ Coverage   90.54%   91.03%   +0.48%     
==========================================
  Files          56       56              
  Lines        2698     2698              
  Branches      355      354       -1     
==========================================
+ Hits         2443     2456      +13     
+ Misses        197      187      -10     
+ Partials       58       55       -3
Impacted Files Coverage Δ
anitya/db/models.py 87.67% <100%> (-0.14%) ⬇️
anitya/ui.py 81.21% <100%> (+1.83%) ⬆️
anitya/api_v2.py 100% <100%> (ø) ⬆️
anitya/lib/utilities.py 89.32% <90%> (+3.6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2323997...8a53dad. Read the comment docs.

cverna
cverna previously approved these changes Sep 19, 2018
Copy link

@cverna cverna left a comment

Choose a reason for hiding this comment

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

LGTM.

@cverna
Copy link

cverna commented Sep 19, 2018

I would suggest to try to keep PRs shorter, this one was not very fun to review since it was a mixed of model change and test coverage increase. Also maybe more than 2 commits would have helped here 🙈

@Zlopez
Copy link
Contributor Author

Zlopez commented Sep 19, 2018

I was actually thought about separating this in two PRs, but in the end I decided to go with one PR.
Next time I will do test coverage raising in separate PR.

@Zlopez
Copy link
Contributor Author

Zlopez commented Oct 2, 2018

Resolved conflict.

@Zlopez
Copy link
Contributor Author

Zlopez commented Oct 16, 2018

I decided to split this PR in two #637 to make it more readable for reviewers. The second one contains only tests and should be merged before this one to make travis pass.

I also added news fragments to this PR.

@Zlopez
Copy link
Contributor Author

Zlopez commented Oct 17, 2018

Handpicked changes from #637 so the tests could pass.

@Zlopez
Copy link
Contributor Author

Zlopez commented Oct 30, 2018

Fixed conflicts and squashed commits.
I will merge this manually.

This should prevent orphaned DB objects.
For example packages without project or distribution.

Signed-off-by: Michal Konečný <[email protected]>
@Zlopez
Copy link
Contributor Author

Zlopez commented Oct 30, 2018

Fixed failing tests, forgot to start tox after conflict resolving.

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.

3 participants