-
Notifications
You must be signed in to change notification settings - Fork 305
Fixes #37859 - Re-drop evr extension in katello #11159
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| #place where monkey patches are required | ||
| require 'monkeys/ar_postgres_evr_t' | ||
| require 'monkeys/fx_sqlite_skip' | ||
| require 'monkeys/remove_hidden_distribution' |
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
160 changes: 160 additions & 0 deletions
160
db/migrate/20240924161240_katello_recreate_evr_constructs.rb
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,160 @@ | ||
| class KatelloRecreateEvrConstructs < ActiveRecord::Migration[6.1] | ||
| def up | ||
| if !extension_enabled?('evr') | ||
| return | ||
| else | ||
| execute <<~SQL | ||
| DROP EXTENSION evr CASCADE; | ||
| SQL | ||
|
|
||
| execute <<~SQL | ||
| create type evr_array_item as ( | ||
| n NUMERIC, | ||
| s TEXT | ||
| ); | ||
|
|
||
| create type evr_t as ( | ||
| epoch INT, | ||
| version evr_array_item[], | ||
| release evr_array_item[] | ||
| ); | ||
|
|
||
| CREATE FUNCTION evr_trigger() RETURNS trigger AS $$ | ||
| BEGIN | ||
| NEW.evr = (select ROW(coalesce(NEW.epoch::numeric,0), | ||
| rpmver_array(coalesce(NEW.version,'empty'))::evr_array_item[], | ||
| rpmver_array(coalesce(NEW.release,'empty'))::evr_array_item[])::evr_t); | ||
| RETURN NEW; | ||
| END; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| create or replace FUNCTION empty(t TEXT) | ||
| RETURNS BOOLEAN as $$ | ||
| BEGIN | ||
| return t ~ '^[[:space:]]*$'; | ||
| END; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| create or replace FUNCTION isalpha(ch CHAR) | ||
| RETURNS BOOLEAN as $$ | ||
| BEGIN | ||
| if ascii(ch) between ascii('a') and ascii('z') or | ||
| ascii(ch) between ascii('A') and ascii('Z') | ||
| then | ||
| return TRUE; | ||
| end if; | ||
| return FALSE; | ||
| END; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| create or replace FUNCTION isalphanum(ch CHAR) | ||
| RETURNS BOOLEAN as $$ | ||
| BEGIN | ||
| if ascii(ch) between ascii('a') and ascii('z') or | ||
| ascii(ch) between ascii('A') and ascii('Z') or | ||
| ascii(ch) between ascii('0') and ascii('9') | ||
| then | ||
| return TRUE; | ||
| end if; | ||
| return FALSE; | ||
| END; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| create or replace function isdigit(ch CHAR) | ||
| RETURNS BOOLEAN as $$ | ||
| BEGIN | ||
| if ascii(ch) between ascii('0') and ascii('9') | ||
| then | ||
| return TRUE; | ||
| end if; | ||
| return FALSE; | ||
| END ; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| create or replace FUNCTION rpmver_array (string1 IN VARCHAR) | ||
| RETURNS evr_array_item[] as $$ | ||
| declare | ||
| str1 VARCHAR := string1; | ||
| digits VARCHAR(10) := '0123456789'; | ||
| lc_alpha VARCHAR(27) := 'abcdefghijklmnopqrstuvwxyz'; | ||
| uc_alpha VARCHAR(27) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
| alpha VARCHAR(54) := lc_alpha || uc_alpha; | ||
| one VARCHAR; | ||
| isnum BOOLEAN; | ||
| ver_array evr_array_item[] := ARRAY[]::evr_array_item[]; | ||
| BEGIN | ||
| if str1 is NULL | ||
| then | ||
| RAISE EXCEPTION 'VALUE_ERROR.'; | ||
| end if; | ||
|
|
||
| one := str1; | ||
| <<segment_loop>> | ||
| while one <> '' | ||
| loop | ||
| declare | ||
| segm1 VARCHAR; | ||
| segm1_n NUMERIC := 0; | ||
| begin | ||
| -- Throw out all non-alphanum characters | ||
| while one <> '' and not isalphanum(one) | ||
| loop | ||
| one := substr(one, 2); | ||
| end loop; | ||
| str1 := one; | ||
| if str1 <> '' and isdigit(str1) | ||
| then | ||
| str1 := ltrim(str1, digits); | ||
| isnum := true; | ||
| else | ||
| str1 := ltrim(str1, alpha); | ||
| isnum := false; | ||
| end if; | ||
| if str1 <> '' | ||
| then segm1 := substr(one, 1, length(one) - length(str1)); | ||
| else segm1 := one; | ||
| end if; | ||
|
|
||
| if segm1 = '' then return ver_array; end if; /* arbitrary */ | ||
| if isnum | ||
| then | ||
| segm1 := ltrim(segm1, '0'); | ||
| if segm1 <> '' then segm1_n := segm1::numeric; end if; | ||
| segm1 := NULL; | ||
| else | ||
| end if; | ||
| ver_array := array_append(ver_array, (segm1_n, segm1)::evr_array_item); | ||
| one := str1; | ||
| end; | ||
| end loop segment_loop; | ||
|
|
||
| return ver_array; | ||
| END ; | ||
| $$ language 'plpgsql'; | ||
|
|
||
| SQL | ||
|
|
||
| add_column :katello_rpms, :evr, :evr_t | ||
| add_column :katello_installed_packages, :evr, :evr_t | ||
|
|
||
| execute <<-SQL | ||
| update katello_rpms SET evr = (ROW(coalesce(epoch::numeric,0), | ||
| rpmver_array(coalesce(version,'empty'))::evr_array_item[], | ||
| rpmver_array(coalesce(release,'empty'))::evr_array_item[])::evr_t); | ||
|
|
||
| update katello_installed_packages SET evr = (ROW(coalesce(epoch::numeric,0), | ||
| rpmver_array(coalesce(version,'empty'))::evr_array_item[], | ||
| rpmver_array(coalesce(release,'empty'))::evr_array_item[])::evr_t); | ||
| SQL | ||
|
|
||
| create_trigger :evr_insert_trigger_katello_rpms, on: :katello_rpms | ||
| create_trigger :evr_update_trigger_katello_rpms, on: :katello_rpms | ||
| create_trigger :evr_insert_trigger_katello_installed_packages, on: :katello_installed_packages | ||
| create_trigger :evr_update_trigger_katello_installed_packages, on: :katello_installed_packages | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| fail ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
This file was deleted.
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.