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 rule_entity_id to rule_evaluations #3999

Merged
merged 4 commits into from
Jul 25, 2024
Merged

Conversation

dmjb
Copy link
Contributor

@dmjb dmjb commented Jul 25, 2024

In order to replace the old evaluation status tables, we need to migrate any evaluation statuses to the new tables which predate the introduction of the new evaluation history tables. In order to simplify this migration, create a foreign key link from rule_evaluations to evaluation_rule_entities (the latter is essentially the new equivalent of the former). A foreign key reference to rule_instances is also added, this is also to simplify the migration.

This PR also fixes some issues with the migration introduced in this previous PR.

Tested locally.

Summary

Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.

Fixes #(related issue)

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.

In order to replace the old evaluation status tables, we need to migrate
any evaluation statuses to the new tables which predate the introduction
of the new evaluation history tables. In order to simplify this
migration, create a foreign key link from `rule_evaluations` to
`evaluation_rule_entities` (the latter is essentially the new equivalent
of the former).

This PR also fixes some issues with the migration introduced in this
previous PR.
@dmjb dmjb requested a review from a team as a code owner July 25, 2024 12:00

-- First, add an ON DELETE CASCADE to the profile_id FK
ALTER TABLE latest_evaluation_statuses DROP CONSTRAINT latest_evaluation_statuses_profile_id_fkey;
ALTER TABLE latest_evaluation_statuses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JAORMX I forgot to add an ON DELETE CASCADE and I think that may have broke things

ON DELETE CASCADE;

-- recreate index with default name
DROP INDEX IF EXISTS idx_profile_id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@blkt Fixed the index name issue here

@@ -129,71 +129,22 @@ func (e *executor) createOrUpdateEvalStatus(
return nil
}

// Upsert evaluation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These DB queries need to happen after the write to the evaluation history table since we are now tracking the rule-entity ID. They also now are run in the same transaction as the other queries.

@coveralls
Copy link

coveralls commented Jul 25, 2024

Coverage Status

coverage: 54.343% (+0.03%) from 54.316%
when pulling 34e12f5 on add-ere-id-rule-evaluations
into 0d7e9b8 on main.

@dmjb dmjb merged commit da3c20b into main Jul 25, 2024
22 checks passed
@dmjb dmjb deleted the add-ere-id-rule-evaluations branch July 25, 2024 12:55
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