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

Refs #37678 - Update evr migration to use DSL #11098

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
17 changes: 7 additions & 10 deletions db/migrate/20240624121212_katello_recreate_evr_constructs.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
class KatelloRecreateEvrConstructs < ActiveRecord::Migration[6.1]
def change
count = select_value <<~SQL
SELECT count(*) FROM pg_extension WHERE extname = 'evr';
SQL
if count.to_i == 0
return
else
execute <<~SQL
DROP EXTENSION evr CASCADE;
SQL
def up
if extension_enabled?('evr')
disable_extension('evr')
Copy link
Member

Choose a reason for hiding this comment

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

If you want the CASCADE option you need to use force: true:

Suggested change
disable_extension('evr')
disable_extension('evr', force: true)

See https://github.com/rails/rails/blob/9ba208c16835f4a174ae9fd385ebc18972d758a4/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L476-L485

Copy link
Member Author

Choose a reason for hiding this comment

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

My dev box is at this version: https://github.com/rails/rails/blob/v6.1.7.8/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb which does a cascade by default and doesn't accept the force parameter.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, so that's something we need to think about when we upgrade. I also now see it should have been force: :cascade.

Copy link
Member

Choose a reason for hiding this comment

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

Is it more dangerous to switch to using disable_extension that could change into a non-cascading removal in the future than to keep using raw SQL?


execute <<~SQL
create type evr_array_item as (
Expand Down Expand Up @@ -156,4 +149,8 @@ def change
create_trigger :evr_update_trigger_katello_installed_packages, on: :katello_installed_packages
end
end

def down
fail ActiveRecord::IrreversibleMigration
end
end
Loading