-
Notifications
You must be signed in to change notification settings - Fork 48
RHINENG-29747: add workspace_id not null constraint #2329
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
database_admin/migrations/167_add_workspace_id_not_null.down.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ALTER TABLE system_inventory ALTER COLUMN workspace_id DROP NOT NULL; | ||
|
|
||
| CREATE OR REPLACE FUNCTION refresh_account_advisory_caches_multi(advisory_ids_in INTEGER[] DEFAULT NULL, | ||
| rh_account_id_in INTEGER DEFAULT NULL) | ||
| RETURNS VOID AS | ||
| $refresh_account_advisory$ | ||
| BEGIN | ||
| PERFORM aa.rh_account_id, aa.workspace_id, aa.advisory_id | ||
| FROM account_advisory aa | ||
| WHERE (aa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (aa.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| FOR UPDATE OF aa; | ||
|
|
||
| WITH current_counts AS ( | ||
| SELECT sa.advisory_id, sa.rh_account_id, si.workspace_id, | ||
| count(sa.*) FILTER (WHERE sa.status_id = 0) AS systems_installable, | ||
| count(sa.*) AS systems_applicable | ||
| FROM system_advisories sa | ||
| JOIN system_inventory si | ||
| ON sa.rh_account_id = si.rh_account_id AND sa.system_id = si.id | ||
| JOIN system_patch sp | ||
| ON si.id = sp.system_id AND sp.rh_account_id = si.rh_account_id | ||
| WHERE sp.last_evaluation IS NOT NULL | ||
| AND si.stale = FALSE | ||
| AND si.workspace_id IS NOT NULL | ||
| AND (sa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (si.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| GROUP BY sa.advisory_id, sa.rh_account_id, si.workspace_id | ||
| ), | ||
| upserted AS ( | ||
| INSERT INTO account_advisory (advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable) | ||
| SELECT advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable | ||
| FROM current_counts | ||
| ON CONFLICT (rh_account_id, workspace_id, advisory_id) DO UPDATE SET | ||
| systems_installable = EXCLUDED.systems_installable, | ||
| systems_applicable = EXCLUDED.systems_applicable | ||
| ) | ||
| DELETE FROM account_advisory | ||
| WHERE (advisory_id, rh_account_id, workspace_id) NOT IN (SELECT advisory_id, rh_account_id, workspace_id FROM current_counts) | ||
| AND (advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL); | ||
| END; | ||
| $refresh_account_advisory$ LANGUAGE plpgsql; |
42 changes: 42 additions & 0 deletions
42
database_admin/migrations/167_add_workspace_id_not_null.up.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ALTER TABLE system_inventory ALTER COLUMN workspace_id SET NOT NULL; | ||
|
|
||
| CREATE OR REPLACE FUNCTION refresh_account_advisory_caches_multi(advisory_ids_in INTEGER[] DEFAULT NULL, | ||
| rh_account_id_in INTEGER DEFAULT NULL) | ||
| RETURNS VOID AS | ||
| $refresh_account_advisory$ | ||
| BEGIN | ||
| PERFORM aa.rh_account_id, aa.workspace_id, aa.advisory_id | ||
| FROM account_advisory aa | ||
| WHERE (aa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (aa.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| FOR UPDATE OF aa; | ||
|
|
||
| WITH current_counts AS ( | ||
| SELECT sa.advisory_id, sa.rh_account_id, si.workspace_id, | ||
| count(sa.*) FILTER (WHERE sa.status_id = 0) AS systems_installable, | ||
| count(sa.*) AS systems_applicable | ||
| FROM system_advisories sa | ||
| JOIN system_inventory si | ||
| ON sa.rh_account_id = si.rh_account_id AND sa.system_id = si.id | ||
| JOIN system_patch sp | ||
| ON si.id = sp.system_id AND sp.rh_account_id = si.rh_account_id | ||
| WHERE sp.last_evaluation IS NOT NULL | ||
| AND si.stale = FALSE | ||
| AND (sa.advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (si.rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL) | ||
| GROUP BY sa.advisory_id, sa.rh_account_id, si.workspace_id | ||
| ), | ||
| upserted AS ( | ||
| INSERT INTO account_advisory (advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable) | ||
| SELECT advisory_id, rh_account_id, workspace_id, systems_installable, systems_applicable | ||
| FROM current_counts | ||
| ON CONFLICT (rh_account_id, workspace_id, advisory_id) DO UPDATE SET | ||
| systems_installable = EXCLUDED.systems_installable, | ||
| systems_applicable = EXCLUDED.systems_applicable | ||
| ) | ||
| DELETE FROM account_advisory | ||
| WHERE (advisory_id, rh_account_id, workspace_id) NOT IN (SELECT advisory_id, rh_account_id, workspace_id FROM current_counts) | ||
| AND (advisory_id = ANY (advisory_ids_in) OR advisory_ids_in IS NULL) | ||
| AND (rh_account_id = rh_account_id_in OR rh_account_id_in IS NULL); | ||
| END; | ||
| $refresh_account_advisory$ LANGUAGE plpgsql; | ||
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.