-
Notifications
You must be signed in to change notification settings - Fork 48
RHINENG-24787: remove system platform sql objects #2161
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
TenSt
merged 3 commits into
RedHatInsights:master
from
TenSt:stepan/RHINENG-24787-remove-system-platform-sql-objects
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
3 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
220 changes: 220 additions & 0 deletions
220
database_admin/migrations/151_drop_system_platform_view.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,220 @@ | ||
| -- system_platform | ||
| DROP TABLE IF EXISTS system_platform; | ||
| CREATE OR REPLACE VIEW system_platform AS SELECT | ||
| si.id, | ||
| si.inventory_id, | ||
| si.rh_account_id, | ||
| si.vmaas_json, | ||
| si.json_checksum, | ||
| si.last_updated, | ||
| si.unchanged_since, | ||
| sp.last_evaluation, | ||
| sp.installable_advisory_count_cache, | ||
| sp.installable_advisory_enh_count_cache, | ||
| sp.installable_advisory_bug_count_cache, | ||
| sp.installable_advisory_sec_count_cache, | ||
| si.last_upload, | ||
| si.stale_timestamp, | ||
| si.stale_warning_timestamp, | ||
| si.culled_timestamp, | ||
| si.stale, | ||
| si.display_name, | ||
| sp.packages_installed, | ||
| sp.packages_installable, | ||
| si.reporter_id, | ||
| sp.third_party, | ||
| si.yum_updates, | ||
| sp.applicable_advisory_count_cache, | ||
| sp.applicable_advisory_enh_count_cache, | ||
| sp.applicable_advisory_bug_count_cache, | ||
| sp.applicable_advisory_sec_count_cache, | ||
| si.satellite_managed, | ||
| si.built_pkgcache, | ||
| sp.packages_applicable, | ||
| sp.template_id, | ||
| si.yum_checksum, | ||
| si.arch, | ||
| si.bootc | ||
| FROM system_inventory si JOIN system_patch sp | ||
| ON si.id = sp.system_id AND si.rh_account_id = sp.rh_account_id; | ||
|
|
||
| CREATE OR REPLACE FUNCTION system_platform_insert() | ||
| RETURNS TRIGGER AS | ||
| $system_platform_insert$ | ||
| DECLARE | ||
| new_system_id BIGINT; | ||
| created TIMESTAMPTZ := CURRENT_TIMESTAMP; | ||
| BEGIN | ||
| INSERT INTO system_inventory ( | ||
| inventory_id, | ||
| rh_account_id, | ||
| vmaas_json, | ||
| json_checksum, | ||
| last_updated, | ||
| unchanged_since, | ||
| last_upload, | ||
| stale_timestamp, | ||
| stale_warning_timestamp, | ||
| culled_timestamp, | ||
| stale, | ||
| display_name, | ||
| reporter_id, | ||
| yum_updates, | ||
| satellite_managed, | ||
| built_pkgcache, | ||
| yum_checksum, | ||
| arch, | ||
| bootc, | ||
| tags, | ||
| created | ||
| ) VALUES ( | ||
| NEW.inventory_id, | ||
| NEW.rh_account_id, | ||
| NEW.vmaas_json, | ||
| NEW.json_checksum, | ||
| NEW.last_updated, | ||
| NEW.unchanged_since, | ||
| NEW.last_upload, | ||
| NEW.stale_timestamp, | ||
| NEW.stale_warning_timestamp, | ||
| NEW.culled_timestamp, | ||
| COALESCE(NEW.stale, false), | ||
| NEW.display_name, | ||
| NEW.reporter_id, | ||
| NEW.yum_updates, | ||
| COALESCE(NEW.satellite_managed, false), | ||
| COALESCE(NEW.built_pkgcache, false), | ||
| NEW.yum_checksum, | ||
| NEW.arch, | ||
| COALESCE(NEW.bootc, false), | ||
| '[]'::JSONB, | ||
| created | ||
| ) | ||
| RETURNING id INTO new_system_id; | ||
|
|
||
| INSERT INTO system_patch ( | ||
| system_id, | ||
| rh_account_id, | ||
| last_evaluation, | ||
| installable_advisory_count_cache, | ||
| installable_advisory_enh_count_cache, | ||
| installable_advisory_bug_count_cache, | ||
| installable_advisory_sec_count_cache, | ||
| packages_installed, | ||
| packages_installable, | ||
| packages_applicable, | ||
| third_party, | ||
| applicable_advisory_count_cache, | ||
| applicable_advisory_enh_count_cache, | ||
| applicable_advisory_bug_count_cache, | ||
| applicable_advisory_sec_count_cache, | ||
| template_id | ||
| ) VALUES ( | ||
| new_system_id, | ||
| NEW.rh_account_id, | ||
| NEW.last_evaluation, | ||
| COALESCE(NEW.installable_advisory_count_cache, 0), | ||
| COALESCE(NEW.installable_advisory_enh_count_cache, 0), | ||
| COALESCE(NEW.installable_advisory_bug_count_cache, 0), | ||
| COALESCE(NEW.installable_advisory_sec_count_cache, 0), | ||
| COALESCE(NEW.packages_installed, 0), | ||
| COALESCE(NEW.packages_installable, 0), | ||
| COALESCE(NEW.packages_applicable, 0), | ||
| COALESCE(NEW.third_party, false), | ||
| COALESCE(NEW.applicable_advisory_count_cache, 0), | ||
| COALESCE(NEW.applicable_advisory_enh_count_cache, 0), | ||
| COALESCE(NEW.applicable_advisory_bug_count_cache, 0), | ||
| COALESCE(NEW.applicable_advisory_sec_count_cache, 0), | ||
| NEW.template_id | ||
| ); | ||
|
|
||
| NEW.id := new_system_id; | ||
| RETURN NEW; | ||
| END; | ||
| $system_platform_insert$ | ||
| LANGUAGE 'plpgsql'; | ||
|
|
||
| CREATE OR REPLACE FUNCTION system_platform_update() | ||
| RETURNS TRIGGER AS | ||
| $system_platform_update$ | ||
| BEGIN | ||
| UPDATE system_inventory SET | ||
| inventory_id = NEW.inventory_id, | ||
| vmaas_json = NEW.vmaas_json, | ||
| json_checksum = NEW.json_checksum, | ||
| last_updated = NEW.last_updated, | ||
| unchanged_since = NEW.unchanged_since, | ||
| last_upload = NEW.last_upload, | ||
| stale_timestamp = NEW.stale_timestamp, | ||
| stale_warning_timestamp = NEW.stale_warning_timestamp, | ||
| culled_timestamp = NEW.culled_timestamp, | ||
| stale = NEW.stale, | ||
| display_name = NEW.display_name, | ||
| reporter_id = NEW.reporter_id, | ||
| yum_updates = NEW.yum_updates, | ||
| satellite_managed = NEW.satellite_managed, | ||
| built_pkgcache = NEW.built_pkgcache, | ||
| yum_checksum = NEW.yum_checksum, | ||
| arch = NEW.arch, | ||
| bootc = NEW.bootc | ||
| WHERE id = OLD.id AND rh_account_id = OLD.rh_account_id; | ||
|
|
||
| UPDATE system_patch SET | ||
| last_evaluation = NEW.last_evaluation, | ||
| installable_advisory_count_cache = NEW.installable_advisory_count_cache, | ||
| installable_advisory_enh_count_cache = NEW.installable_advisory_enh_count_cache, | ||
| installable_advisory_bug_count_cache = NEW.installable_advisory_bug_count_cache, | ||
| installable_advisory_sec_count_cache = NEW.installable_advisory_sec_count_cache, | ||
| packages_installed = NEW.packages_installed, | ||
| packages_installable = NEW.packages_installable, | ||
| packages_applicable = NEW.packages_applicable, | ||
| third_party = NEW.third_party, | ||
| applicable_advisory_count_cache = NEW.applicable_advisory_count_cache, | ||
| applicable_advisory_enh_count_cache = NEW.applicable_advisory_enh_count_cache, | ||
| applicable_advisory_bug_count_cache = NEW.applicable_advisory_bug_count_cache, | ||
| applicable_advisory_sec_count_cache = NEW.applicable_advisory_sec_count_cache, | ||
| template_id = NEW.template_id | ||
| WHERE system_id = OLD.id AND rh_account_id = OLD.rh_account_id; | ||
|
|
||
| RETURN NEW; | ||
| END; | ||
| $system_platform_update$ | ||
| LANGUAGE 'plpgsql'; | ||
|
|
||
| CREATE OR REPLACE FUNCTION system_platform_delete() | ||
| RETURNS TRIGGER AS | ||
| $system_platform_delete$ | ||
| BEGIN | ||
| DELETE FROM system_patch | ||
| WHERE system_id = OLD.id AND rh_account_id = OLD.rh_account_id; | ||
|
|
||
| DELETE FROM system_inventory | ||
| WHERE id = OLD.id AND rh_account_id = OLD.rh_account_id; | ||
|
|
||
| RETURN OLD; | ||
| END; | ||
| $system_platform_delete$ | ||
| LANGUAGE 'plpgsql'; | ||
|
|
||
| CREATE TRIGGER system_platform_insert_trigger | ||
| INSTEAD OF INSERT ON system_platform | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION system_platform_insert(); | ||
|
|
||
| CREATE TRIGGER system_platform_update_trigger | ||
| INSTEAD OF UPDATE ON system_platform | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION system_platform_update(); | ||
|
|
||
| CREATE TRIGGER system_platform_delete_trigger | ||
| INSTEAD OF DELETE ON system_platform | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION system_platform_delete(); | ||
|
|
||
| GRANT SELECT, INSERT, UPDATE, DELETE ON system_platform TO listener; | ||
| -- evaluator needs to update last_evaluation | ||
| GRANT UPDATE ON system_platform TO evaluator; | ||
| -- manager needs to update cache and delete systems | ||
| GRANT SELECT, UPDATE, DELETE ON system_platform TO manager; | ||
| -- VMaaS sync needs to be able to perform system culling tasks | ||
| GRANT SELECT, UPDATE, DELETE ON system_platform to vmaas_sync; |
9 changes: 9 additions & 0 deletions
9
database_admin/migrations/151_drop_system_platform_view.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,9 @@ | ||
| DROP TRIGGER IF EXISTS system_platform_delete_trigger ON system_platform; | ||
| DROP TRIGGER IF EXISTS system_platform_update_trigger ON system_platform; | ||
| DROP TRIGGER IF EXISTS system_platform_insert_trigger ON system_platform; | ||
|
|
||
| DROP FUNCTION IF EXISTS system_platform_delete(); | ||
| DROP FUNCTION IF EXISTS system_platform_update(); | ||
| DROP FUNCTION IF EXISTS system_platform_insert(); | ||
|
|
||
| DROP VIEW IF EXISTS system_platform; |
5 changes: 5 additions & 0 deletions
5
database_admin/migrations/152_narrow_manager_inventory_patch_privileges.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,5 @@ | ||
| REVOKE UPDATE ON system_patch FROM manager; | ||
| GRANT UPDATE ON system_patch TO manager; | ||
|
|
||
| REVOKE UPDATE ON system_inventory FROM manager; | ||
| GRANT UPDATE ON system_inventory TO manager; | ||
16 changes: 16 additions & 0 deletions
16
database_admin/migrations/152_narrow_manager_inventory_patch_privileges.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,16 @@ | ||
| -- Restore least-privilege grants for manager after migration 145 temporarily | ||
| -- broadened them for system_platform view/trigger updates (removed in 151). | ||
| REVOKE UPDATE ON system_inventory FROM manager; | ||
| GRANT UPDATE (stale) ON system_inventory TO manager; | ||
|
|
||
| REVOKE UPDATE ON system_patch FROM manager; | ||
| GRANT UPDATE ( | ||
| installable_advisory_count_cache, | ||
| installable_advisory_enh_count_cache, | ||
| installable_advisory_bug_count_cache, | ||
| installable_advisory_sec_count_cache, | ||
| applicable_advisory_count_cache, | ||
| applicable_advisory_enh_count_cache, | ||
| applicable_advisory_bug_count_cache, | ||
| applicable_advisory_sec_count_cache, | ||
| template_id) ON system_patch TO manager; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of revoking and granting UPDATE back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The column-wide and table-wide privileges are distinct in postgres. So just granting privileges on the table level will leave privileges on the column level.
REVOKEon the table level however also removes the column level privileges. So this is done to be consistent - remove all update privileges (column and table) and then assign just table privileges. Same approach is done in the "up" migration.