fix: update foreign key constraints and ensure uniqueness in runner metadata#73
Open
fix: update foreign key constraints and ensure uniqueness in runner metadata#73
Conversation
Member
|
Why do we put an overly complicated trigger when we should just do a drop cascade with the foreign keys on upsert (conflict should drop old row and insert new one) |
13f0cbd to
57591ea
Compare
Author
I’ve simplified it |
check on conflict is not necessary anymore as we remove the row beforehand
lalepee
approved these changes
Apr 10, 2026
Collaborator
lalepee
left a comment
There was a problem hiding this comment.
Ok for me. I didn't found a better way to do the check on the existence of the foreign key constraint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes several issues identified in COAL, specifically in the part responsible for sending data to PostgreSQL.
These issues are mainly related to the function that creates the link between the comsotech_runmetadata table and the result tables exported to PostgreSQL.
First issue: there was a syntax error in the statement used to define the foreign key constraint. The ADD keyword was missing in the ALTER TABLE statement when declaring the constraint.
Second issue: the foreign key constraint was being added to the wrong table name, without the expected prefix. For example, it targeted mytable instead of cosmotech_mytable by default.
Third issue: the last_csm_run_id column was missing a uniqueness constraint, which caused the creation of the foreign key constraint to fail.
Fourth issue: the code did not check whether the foreign key constraint already existed before attempting to create it. As a result, each write operation tried to recreate the constraint, which is not allowed by PostgreSQL.
Fifth and final issue: when the same scenario was executed two or more times, data from the previous run was not deleted. This caused the insertion query into the runner_metadata table to fail because of the uniqueness constraint.
Each of these issues has been fixed and tested in a development environment.
However, some cases are still not handled, such as deleting a scenario, which currently does not remove the related data from the database.
One important remaining point is that we need to find an efficient way to test all these behaviors through integration tests directly in COAL.