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

WIP: Remove per-entity tables #4279

Closed
wants to merge 2 commits into from
Closed

WIP: Remove per-entity tables #4279

wants to merge 2 commits into from

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Aug 26, 2024

Summary

Fixes #4315

Change Type

Mark the type of change your PR introduces:

  • 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

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

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.

@jhrozek
Copy link
Contributor

jhrozek commented Aug 26, 2024

About the failures in artifact.go - I wonder if the path of least resistance (even with a bit of manual coding that might be thrown away later) would be to substitute the database lookups like GetArtifact with wrappers around GetEntity that would for now fulfill the same contract, in case of GetArtifact still return a pb.Artifact.

@@ -20,4 +20,72 @@ DROP TABLE IF EXISTS repositories;
DROP TABLE IF EXISTS artifacts;
DROP TABLE IF EXISTS pull_requests;

CREATE VIEW repositories AS
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not as familiar with views and especially replacing tables with views, so maybe this is a dumb question - but how do indexes work?

Also comparing the columns, would we miss something by not having the reminder_last_sent and updated_at columns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we don´t really care as much about the updated_at since we care now about properties. I do wonder how reminder_last_sent would work... would that need to be then part of the central table? maybe it needs to be.

Signed-off-by: Juan Antonio Osorio <[email protected]>
@JAORMX JAORMX force-pushed the rm-entity-tables branch 3 times, most recently from ad94b18 to 5dd7869 Compare August 28, 2024 11:05
Copy link
Contributor

@blkt blkt left a comment

Choose a reason for hiding this comment

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

Awesome work!

Comment on lines +133 to +134
ei.entity_type,
ere.entity_instance_id as entity_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm sorry, I could not unsee it 😂

Suggested change
ei.entity_type,
ere.entity_instance_id as entity_id,
ei.entity_type,
ere.entity_instance_id as entity_id,

pr.pr_number,
a.artifact_name,
j.id as project_id,
ei.name as entity_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: this need to be used in the WHERE condition as well.

FROM evaluation_statuses s
JOIN evaluation_rule_entities ere ON s.rule_entity_id = ere.id
LEFT JOIN entity_instances AS ei ON ei.id = ere.entity_instance_id
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: IIRC there is an ON DELETE CASCADE clause in the foreign key of from evaluation_rule_entities, so this should be a plain JOIN.

Is there a particular reason why this is a LEFT JOIN instead? Was data migrated to the new table?

Comment on lines 88 to 94
WHERE les.profile_id = $1 AND
(
CASE
WHEN sqlc.narg(entity_type)::entities = 'repository' AND ere.repository_id = sqlc.narg(entity_id)::UUID THEN true
WHEN sqlc.narg(entity_type)::entities = 'artifact' AND ere.artifact_id = sqlc.narg(entity_id)::UUID THEN true
WHEN sqlc.narg(entity_type)::entities = 'pull_request' AND ere.pull_request_id = sqlc.narg(entity_id)::UUID THEN true
WHEN ei.entity_id = sqlc.narg(entity_id)::UUID THEN true
WHEN sqlc.narg(entity_id)::UUID IS NULL THEN true
ELSE false
END
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: very, very minor thing, but I would take the chance to rewrite this into the following

WHERE les.profile_id = $1
  AND (sqlc.narg(entity_id)::UUID IS NULL OR sqlc.narg(entity_id)::UUID = ei.entity_id)

Copy link
Contributor

This PR needs additional information before we can continue. It is now marked as stale because it has been open for 30 days with no activity. Please provide the necessary details to continue or it will be closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 29, 2024
@JAORMX JAORMX closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use entity_instances table for entity information
3 participants