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 project id foreign key to data sources tables. #5026

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

blkt
Copy link
Contributor

@blkt blkt commented Nov 22, 2024

Summary

Tables data_sources_functions and rule_type_data_sources added by migration 108 lacked a reference to their containing project.

This change adds project_id foreign key in the style of rule_instances in order to avoid future mistakes like exposing resouces by id to users that don't have rights on the containing project.

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Manually ran migrate up and migrate down in a database containing a few records. The aim of the test was to verify that the calculated project id was correct.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

Tables `data_sources_functions` and `rule_type_data_sources` added by
migration 108 lacked a reference to their containing project.

This change adds `project_id` foreign key in the style of
`rule_instances` in order to avoid future mistakes like exposing
resouces by id to users that don't have rights on the containing
project.
@blkt blkt self-assigned this Nov 22, 2024
@blkt blkt requested a review from a team as a code owner November 22, 2024 13:48
@coveralls
Copy link

Coverage Status

coverage: 54.63% (+0.003%) from 54.627%
when pulling cedff51 on fix/data_sources_migration_project_id
into c8469dd on main.

Comment on lines +26 to +33
BEGIN
FOR ds_id, pj_id IN SELECT id, project_id FROM data_sources
LOOP
UPDATE data_sources_functions
SET project_id = pj_id
WHERE data_source_id = ds_id;
END LOOP;
END $$;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this and the loop below be optimised using a JOIN?

e.g.:

UPDATE data_sources_functions dsf
SET project_id = ds.project_id
FROM data_sources ds
WHERE dsf.data_source_id = ds.id;

@JAORMX JAORMX merged commit 5183ed0 into main Nov 25, 2024
26 of 27 checks passed
@JAORMX JAORMX deleted the fix/data_sources_migration_project_id branch November 25, 2024 05:52
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.

4 participants