Skip to content
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

Fixes #37859 - Re-drop evr extension in katello #11159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/initializers/monkeys.rb
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'
127 changes: 126 additions & 1 deletion db/migrate/20200213184848_create_evr_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,132 @@ class CreateEvrType < ActiveRecord::Migration[5.2]
def up
unless connection.adapter_name.downcase.include?('sqlite')

enable_extension "evr"
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
Expand Down
160 changes: 160 additions & 0 deletions db/migrate/20240924161240_katello_recreate_evr_constructs.rb
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
Comment on lines +6 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
execute <<~SQL
DROP EXTENSION evr CASCADE;
SQL
begin
execute <<~SQL
DROP EXTENSION evr CASCADE;
SQL
rescue ActiveRecord::StatementInvalid
msg = _('Due to the PostgreSQL 12 to 13 upgade, run' \
" UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman');" \
" as a PostgreSQL admin before migrating the database.")
raise ActiveRecord::StatementInvalid, msg
end

The logs looks like this as a result:

== 20240924161240 KatelloRecreateEvrConstructs: migrating =====================
-- extension_enabled?("evr")
   -> 0.0014s
-- execute("DROP EXTENSION evr CASCADE;\n")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Due to the PostgreSQL 12 to 13 upgade, run UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman'); as a PostgreSQL admin before migrating the database.
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:14:in `rescue in up'
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:6:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `public_send'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:849:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:209:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1086:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/gems/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'

Caused by:
ActiveRecord::StatementInvalid: Due to the PostgreSQL 12 to 13 upgade, run UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman'); as a PostgreSQL admin before migrating the database.
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:14:in `rescue in up'
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:6:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `public_send'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:849:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:209:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1086:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/gems/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'

Caused by:
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  must be owner of extension evr
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `exec'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `block (2 levels) in execute'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block in execute'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `execute'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:929:in `block in method_missing'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:897:in `block in say_with_time'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:897:in `say_with_time'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:918:in `method_missing'
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:7:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `public_send'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:849:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:209:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1086:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/gems/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'

Caused by:
PG::InsufficientPrivilege: ERROR:  must be owner of extension evr
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `exec'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:49:in `block (2 levels) in execute'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:48:in `block in execute'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:47:in `execute'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:929:in `block in method_missing'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:897:in `block in say_with_time'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:897:in `say_with_time'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:918:in `method_missing'
/usr/share/gems/gems/katello-4.15.0.pre.master/db/migrate/20240924161240_katello_recreate_evr_constructs.rb:7:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `public_send'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:849:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `block in ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/gems/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:209:in `transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1380:in `ddl_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1086:in `up'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/gems/gems/activerecord-6.1.7.8/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/gems/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be just for remote database users. We can discuss later with @ekohl if it makes sense for the installer to also catch this issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is being added to the installer here: theforeman/foreman-installer#984

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, partially. I suppose this change would make the error more obvious in case of weird edge case issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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
13 changes: 0 additions & 13 deletions lib/monkeys/fx_sqlite_skip.rb

This file was deleted.

Loading