-
Notifications
You must be signed in to change notification settings - Fork 73
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
Eliminate orphan objects #3732
base: master
Are you sure you want to change the base?
Eliminate orphan objects #3732
Conversation
@akostadinov Updated |
@@ -6,72 +6,27 @@ namespace :database do | |||
puts 'Checking and removing orphaned objects...' | |||
|
|||
# Tables to exclude from orphaned objects check | |||
excluded_tables = ['accounts', 'audits', 'categories', 'category_types', 'cms_templates', 'legal_term_acceptances', 'legal_term_bindings', | |||
'legal_term_versions', 'proxy_logs', 'schema_migrations', 'service_cubert_infos', 'slugs', 'taggings', 'tags'] | |||
excluded_tables = ['cms_templates'] |
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.
Why exclude this?
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.
I think this exclusion can be removed
|
||
if orphaned_objects.exists? | ||
puts "Found orphaned objects in #{model.table_name}:" | ||
orphaned_objects.each { |obj| puts "- ID: #{obj.id}, Tenant ID: #{obj.tenant_id}" } |
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.
I'd use find_each
here instead of each
to use batching.
89a470f
to
8e47c60
Compare
I rebased this, It was too old. |
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.
A wrote a couple of comments but this LGTM. I haven't tried to run the script locally though.
It would be good to write a couple of tests. Do we have tests for rake tasks?
@@ -0,0 +1,32 @@ | |||
# frozen_string_literal: true | |||
|
|||
namespace :database do |
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.
Shouldn't we use the db
namespace? to be consistent with all other DB tasks
@@ -6,72 +6,27 @@ namespace :database do | |||
puts 'Checking and removing orphaned objects...' | |||
|
|||
# Tables to exclude from orphaned objects check | |||
excluded_tables = ['accounts', 'audits', 'categories', 'category_types', 'cms_templates', 'legal_term_acceptances', 'legal_term_bindings', | |||
'legal_term_versions', 'proxy_logs', 'schema_migrations', 'service_cubert_infos', 'slugs', 'taggings', 'tags'] | |||
excluded_tables = ['cms_templates'] |
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.
I think this exclusion can be removed
|
||
provider_account_ids = Account.where(provider: true).pluck(:id) | ||
|
||
ActiveRecord::Base.descendants.each do |model| |
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.
Better this IMO:
ActiveRecord::Base.descendants.each do |model| | |
ApplicationRecord.descendants.each do |model| |
What this PR does / why we need it:
We need a rake task to go over all tables with the
tenant_id
field and make check whether that tenant still exists, reporting and optionally removing these on the way.complete description is in JIRA
Which issue(s) this PR fixes
https://issues.redhat.com/browse/THREESCALE-10855
Note: I have commented the deleted line for now but added puts so whoever will run it while reviewing can see the puts