-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-qcmx-gv2g-v767
Advisory fix cascade delete
- Loading branch information
Showing
5 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Sequel.migration do | ||
up do | ||
# Remove orphan secret so turning its resource ID to foreign key will work | ||
execute <<-DELETE | ||
DELETE FROM secrets | ||
WHERE NOT EXISTS ( | ||
SELECT 1 FROM resources | ||
WHERE secrets.resource_id = resource_id | ||
) | ||
DELETE | ||
# Create cascade delete relationship between resource and secret so when resource deleted its secrets are deleted too | ||
alter_table :secrets do | ||
add_foreign_key [:resource_id], :resources, on_delete: :cascade | ||
add_index :resource_id | ||
end | ||
end | ||
|
||
down do | ||
alter_table :secrets do | ||
drop_foreign_key [:resource_id] | ||
drop_index :resource_id | ||
end | ||
end | ||
end |