Skip to content

Add unique index on merge_request_diff_llm_summaries

Patrick Bajao requested to merge pb-add-unique-index-mr-diff-llm-summaries into master

What does this MR do and why?

In !118812 (diffs), a has_one :merge_request_diff_llm_summary association will be added to MergeRequestDiff. As noted in !121656 (comment 1408464527), there should only be one merge_request_diff_llm_summaries record per merge_request_diff_id.

This adds uniqueness validation and a unique index on merge_request_diff_id.

Removes the existing index on merge_request_diff_id since it'll be duplicated.

As of this writing, there are no records in merge_request_diff_llm_summaries table yet since no code is creating a record for it yet.

Migration

db:migrate

main: == [advisory_lock_connection] object_id: 279380, pg_backend_pid: 71392
main: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: migrating =======
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0818s
main: -- index_exists?(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id", :unique=>true, :algorithm=>:concurrently})
main:    -> 0.0023s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- add_index(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id", :unique=>true, :algorithm=>:concurrently})
main:    -> 0.0016s
main: -- execute("RESET statement_timeout")
main:    -> 0.0001s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0003s
main: -- indexes(:merge_request_diff_llm_summaries)
main:    -> 0.0015s
main: -- remove_index(:merge_request_diff_llm_summaries, {:algorithm=>:concurrently, :name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id"})
main:    -> 0.0034s
main: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: migrated (0.1049s) 

main: == [advisory_lock_connection] object_id: 279380, pg_backend_pid: 71392
ci: == [advisory_lock_connection] object_id: 279600, pg_backend_pid: 71394
ci: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: migrating =======
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0006s
ci: -- index_exists?(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id", :unique=>true, :algorithm=>:concurrently})
ci:    -> 0.0022s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- add_index(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id", :unique=>true, :algorithm=>:concurrently})
ci:    -> 0.0019s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0002s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0003s
ci: -- indexes(:merge_request_diff_llm_summaries)
ci:    -> 0.0015s
ci: -- remove_index(:merge_request_diff_llm_summaries, {:algorithm=>:concurrently, :name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id"})
ci:    -> 0.0021s
ci: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: migrated (0.0217s)

db:rollback

main: == [advisory_lock_connection] object_id: 279100, pg_backend_pid: 77123
main: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: reverting =======
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0780s
main: -- index_exists?(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id", :algorithm=>:concurrently})
main:    -> 0.0021s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- add_index(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id", :algorithm=>:concurrently})
main:    -> 0.0020s
main: -- execute("RESET statement_timeout")
main:    -> 0.0001s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0004s
main: -- indexes(:merge_request_diff_llm_summaries)
main:    -> 0.0014s
main: -- remove_index(:merge_request_diff_llm_summaries, {:algorithm=>:concurrently, :name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id"})
main:    -> 0.0021s
main: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: reverted (0.1009s) 

main: == [advisory_lock_connection] object_id: 279100, pg_backend_pid: 77123
ci: == [advisory_lock_connection] object_id: 297680, pg_backend_pid: 77497
ci: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: reverting =======
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0006s
ci: -- index_exists?(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id", :algorithm=>:concurrently})
ci:    -> 0.0025s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- add_index(:merge_request_diff_llm_summaries, :merge_request_diff_id, {:name=>"index_merge_request_diff_llm_summaries_on_mr_diff_id", :algorithm=>:concurrently})
ci:    -> 0.0020s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0002s
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0005s
ci: -- indexes(:merge_request_diff_llm_summaries)
ci:    -> 0.0017s
ci: -- remove_index(:merge_request_diff_llm_summaries, {:algorithm=>:concurrently, :name=>"unique_merge_request_diff_llm_summaries_on_mr_diff_id"})
ci:    -> 0.0015s
ci: == 20230601084041 AddMergeRequestDiffLlmSummariesUniqueIndex: reverted (0.0253s) 

ci: == [advisory_lock_connection] object_id: 297680, pg_backend_pid: 77497

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading