Updates ForeignKeys to Ml::Candidate to be on_delete: :cascade
What does this MR do and why?
Instances of Ml::Candidate can't be deleted due to FK constraints not properly set to :cascade.
How to set up and validate locally
-
Create an experiment, candidate and dependencies
exp = Ml::Experiment.create!(name: "Gitlab Experiment", user_id: user_id, project_id: project_id) c = exp.candidates.create!(user_id: user_id, start_time: 0) } c.metrics.create!(name: "auc", value: 0.1 , tracked_at: Time.zone.now, step: 1) c.params.create!(name: "algorithm", value: "DecisionTree" ) c.metadata.create!(name: "foo", value: "bar" )
-
Delete the candidate
c.destroy
-
Metadata, Params and Metrics should be empty
Ml::CandidateMetadata.count #0 Ml::CandidateParam.count #0 Ml::CandidateMetric.count #0
Database Migrations
Tables are small (less than 1000 rows)
UP
main: == 20230330101438 CreateFkMlCandidateParamsOnCandidateId: migrating ===========
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE ml_candidate_params ADD CONSTRAINT fk_ml_candidate_params_on_candidate_id FOREIGN KEY (candidate_id) REFERENCES ml_candidates (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0017s
main: == 20230330101438 CreateFkMlCandidateParamsOnCandidateId: migrated (0.1711s) ==
main: == 20230330101439 ValidateFkMlCandidateParamsOnCandidateId: migrating =========
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0018s
main: -- execute("ALTER TABLE ml_candidate_params VALIDATE CONSTRAINT fk_ml_candidate_params_on_candidate_id;")
main: -> 0.0017s
main: -- execute("RESET statement_timeout")
main: -> 0.0004s
main: == 20230330101439 ValidateFkMlCandidateParamsOnCandidateId: migrated (0.0139s)
main: == 20230330101440 RemoveOldFkMlCandidateParamsOnCandidateId: migrating ========
main: -- remove_foreign_key(:ml_candidate_params, {:column=>:candidate_id, :name=>"fk_rails_d4a51d1185"})
main: -> 0.0037s
main: == 20230330101440 RemoveOldFkMlCandidateParamsOnCandidateId: migrated (0.0105s)
main: == 20230330101441 CreateFkMlCandidateMetricsOnCandidateId: migrating ==========
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE ml_candidate_metrics ADD CONSTRAINT fk_ml_candidate_metrics_on_candidate_id FOREIGN KEY (candidate_id) REFERENCES ml_candidates (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0009s
main: == 20230330101441 CreateFkMlCandidateMetricsOnCandidateId: migrated (0.0362s) =
main: == 20230330101442 ValidateFkMlCandidateMetricsOnCandidateId: migrating ========
main: -- execute("ALTER TABLE ml_candidate_metrics VALIDATE CONSTRAINT fk_ml_candidate_metrics_on_candidate_id;")
main: -> 0.0008s
main: == 20230330101442 ValidateFkMlCandidateMetricsOnCandidateId: migrated (0.0075s)
main: == 20230330101443 RemoveOldFkMlCandidateMetricsOnCandidateId: migrating =======
main: -- remove_foreign_key(:ml_candidate_metrics, {:column=>:candidate_id, :name=>"fk_rails_efb613a25a"})
main: -> 0.0045s
main: == 20230330101443 RemoveOldFkMlCandidateMetricsOnCandidateId: migrated (0.1382s)
DOWN
main: == 20230330101443 RemoveOldFkMlCandidateMetricsOnCandidateId: reverting =======
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE ml_candidate_params ADD CONSTRAINT fk_rails_efb613a25a FOREIGN KEY (candidate_id) REFERENCES ml_candidates (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0045s
main: == 20230330101443 RemoveOldFkMlCandidateMetricsOnCandidateId: reverted (0.1517s)
main: == 20230330101442 ValidateFkMlCandidateMetricsOnCandidateId: reverting ========
main: == 20230330101442 ValidateFkMlCandidateMetricsOnCandidateId: reverted (0.0032s)
main: == 20230330101441 CreateFkMlCandidateMetricsOnCandidateId: reverting ==========
main: -- transaction_open?()
main: -> 0.0000s
main: -- remove_foreign_key(:ml_candidate_metrics, {:column=>:candidate_id, :on_delete=>:cascade, :name=>"fk_ml_candidate_metrics_on_candidate_id"})
main: -> 0.0027s
main: == 20230330101441 CreateFkMlCandidateMetricsOnCandidateId: reverted (0.0132s) =
main: == 20230330101440 RemoveOldFkMlCandidateParamsOnCandidateId: reverting ========
main: -- transaction_open?()
main: -> 0.0001s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE ml_candidate_params ADD CONSTRAINT fk_rails_d4a51d1185 FOREIGN KEY (candidate_id) REFERENCES ml_candidates (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0006s
main: == 20230330101440 RemoveOldFkMlCandidateParamsOnCandidateId: reverted (0.0145s)
main: == 20230330101439 ValidateFkMlCandidateParamsOnCandidateId: reverting =========
main: == 20230330101439 ValidateFkMlCandidateParamsOnCandidateId: reverted (0.0027s)
main: == 20230330101438 CreateFkMlCandidateParamsOnCandidateId: reverting ===========
main: -- transaction_open?()
main: -> 0.0000s
main: -- remove_foreign_key(:ml_candidate_params, {:column=>:candidate_id, :on_delete=>:cascade, :name=>"fk_ml_candidate_params_on_candidate_id"})
main: -> 0.0021s
main: == 20230330101438 CreateFkMlCandidateParamsOnCandidateId: reverted (0.0102s) ==
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 Eduardo Bonet