Remove redundant foreign_key_exists? check in LFK script
What does this MR do and why?
This MR removes the redundant foreign_key_exists?
check in the LFK script because remove_foreign_key_if_exists
is called right below and this method does the same check internally.
Script generation works and migrations run successfully after this change.
Migration generated by script:
class RemoveProjectsPagesDeploymentsProjectIdFk < Gitlab::Database::Migration[2.1]
disable_ddl_transaction!
FOREIGN_KEY_NAME = "fk_rails_993b88f59a"
def up
with_lock_retries do
remove_foreign_key_if_exists(:pages_deployments, :projects,
name: FOREIGN_KEY_NAME, reverse_lock_order: true)
end
end
def down
add_concurrent_foreign_key(:pages_deployments, :projects,
name: FOREIGN_KEY_NAME, column: :project_id,
target_column: :id, on_delete: :cascade)
end
end
Migration output
main: == [advisory_lock_connection] object_id: 249100, pg_backend_pid: 5778
main: == 20230828123652 RemoveProjectsPagesDeploymentsProjectIdFk: migrating ========
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("LOCK TABLE projects, pages_deployments IN ACCESS EXCLUSIVE MODE")
main: -> 0.0004s
main: -- remove_foreign_key(:pages_deployments, :projects, {:name=>"fk_rails_993b88f59a"})
main: -> 0.0074s
main: == 20230828123652 RemoveProjectsPagesDeploymentsProjectIdFk: migrated (0.0257s)
main: == [advisory_lock_connection] object_id: 249100, pg_backend_pid: 5778
ci: == [advisory_lock_connection] object_id: 269540, pg_backend_pid: 5780
ci: == 20230828123652 RemoveProjectsPagesDeploymentsProjectIdFk: migrating ========
ci: -- transaction_open?()
ci: -> 0.0000s
ci: -- transaction_open?()
ci: -> 0.0000s
ci: -- execute("LOCK TABLE projects, pages_deployments IN ACCESS EXCLUSIVE MODE")
ci: -> 0.0013s
ci: -- remove_foreign_key(:pages_deployments, :projects, {:name=>"fk_rails_993b88f59a"})
ci: -> 0.0099s
ci: == 20230828123652 RemoveProjectsPagesDeploymentsProjectIdFk: migrated (0.0386s)
ci: == [advisory_lock_connection] object_id: 269540, pg_backend_pid: 5780
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Manoj M J