-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHINENG-5394: migrate system_package per account
Co-authored-by: dkuc <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
database_admin/migrations/119_migrate_system_package2.up.sql
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,41 @@ | ||
CREATE OR REPLACE PROCEDURE copy_system_packages() | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
cnt bigint := 0; | ||
prev_cnt bigint := 0; | ||
rows_inserted bigint := 0; | ||
account int := 0; | ||
BEGIN | ||
FOR account IN (SELECT id from rh_account ORDER BY hash_partition_id(id, 128), id) | ||
LOOP | ||
INSERT INTO system_package2 | ||
SELECT system_package.rh_account_id, | ||
system_id, | ||
name_id, | ||
package_id, | ||
(SELECT id | ||
FROM package | ||
WHERE package.name_id = system_package.name_id | ||
AND evra = | ||
JSONB_PATH_QUERY_ARRAY(update_data, '$[*] ? (@.status== "Installable").evra') ->> 0), | ||
(SELECT id | ||
FROM package | ||
WHERE package.name_id = system_package.name_id | ||
AND evra = JSONB_PATH_QUERY_ARRAY(update_data, '$[*] ? (@.status== "Applicable").evra') ->> 0) | ||
FROM system_package | ||
JOIN system_platform ON system_platform.id = system_package.system_id AND system_platform.rh_account_id = system_package.rh_account_id | ||
WHERE system_package.rh_account_id = account; | ||
COMMIT; | ||
|
||
GET DIAGNOSTICS rows_inserted = ROW_COUNT; | ||
|
||
cnt := cnt + rows_inserted; | ||
IF (cnt/1000000)::int > (prev_cnt/1000000)::int THEN | ||
RAISE NOTICE 'inserted % rows, account: %, partition: %', cnt, account, hash_partition_id(account, 128); | ||
prev_cnt := cnt; | ||
END IF; | ||
END LOOP; | ||
END | ||
$$; |
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