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

Drop only existing foreign_keys #240

Merged
merged 1 commit into from Dec 16, 2021

Conversation

ezr-ondrej
Copy link
Member

Fixes #239

Copy link

@vsedmik vsedmik left a comment

Choose a reason for hiding this comment

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

ACK this patch fixed the issue

remove_foreign_key 'host_classes', 'puppetclasses', name: 'host_classes_puppetclass_id_fk'
remove_foreign_key 'operatingsystems_puppetclasses', 'operatingsystems', name: 'operatingsystems_puppetclasses_operatingsystem_id_fk'
remove_foreign_key 'operatingsystems_puppetclasses', 'puppetclasses', name: 'operatingsystems_puppetclasses_puppetclass_id_fk'
remove_foreign_key('host_classes', 'hosts') if foreign_key_exists?(:host_classes, :hosts)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any idea whether this error can occur for the other migrations?

Copy link
Member Author

Choose a reason for hiding this comment

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

no idea if it can, it didn't in Satellite usecase, but I can add the condition to all of them :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't hurt I guess :) Any idea why the error occurred in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it was because of the FK was created with the table alrady and thus had a default name, not the name given by us.

@nadjaheitmann
Copy link
Collaborator

Could you please add a more descriptive commit message :)

Some foreign keys have been already created with other names or not created at all.
This adds a security measure to remove the key whatever the name is if it exists.

Fixes theforeman#239
@ezr-ondrej ezr-ondrej changed the title Drop foreign_key whatever it name is Drop only existing foreign_keys Dec 16, 2021
@ezr-ondrej
Copy link
Member Author

Better? :)

@nadjaheitmann
Copy link
Collaborator

LGTM! Thanks @ezr-ondrej

@ezr-ondrej ezr-ondrej merged commit 4c0712d into theforeman:master Dec 16, 2021
@ezr-ondrej ezr-ondrej deleted the fix_purge_task branch December 16, 2021 11:04
@ezr-ondrej
Copy link
Member Author

CP 2.0: 6b5f43a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Puppet disable command fails
3 participants