Skip to content

Debian package uniqueness

Current behavior of Debian packages is to enforce unicity on (name, version, distribution) within a project (when debian? && !version.nil?) with condition not_pending_destruction.

In the future, we may need to support publishing a package to several distributions (i.e changing has_one :debian_publication to has_many :debian_publication). We may also need to change the model to improve performance.

Using stricter validations, will reduce the risk of problems like we have in Helm package (!107317 (comment 1219775268)).

After this MR, the unicity is enforced on (name, version) within a project (when debian?) with condition not_pending_destruction.

This MR is first part of #389228.

Migrations:

unning: `bundle exec rake db:migrate:main`
main: == 20230317075852 AddTmpUniquePackagesIndexWhenDebian: migrating ==============
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0182s
main: -- index_exists?(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4 AND\n        created_at > TIMESTAMP WITH TIME ZONE '2023-03-23 08:48:06 UTC'", :unique=>true, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0141s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0005s
main: -- add_index(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4 AND\n        created_at > TIMESTAMP WITH TIME ZONE '2023-03-23 08:48:06 UTC'", :unique=>true, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0018s
main: -- execute("RESET statement_timeout")
main:    -> 0.0004s
main: == 20230317075852 AddTmpUniquePackagesIndexWhenDebian: migrated (0.0569s) =====
main: == 20230317080000 EnsureUniqueDebianPackages: migrating =======================
main: == 20230317080000 EnsureUniqueDebianPackages: migrated (0.0090s) ==============
main: == 20230317080137 AddUniquePackagesIndexWhenDebian: migrating =================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0008s
main: -- index_exists?(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4", :unique=>true, :name=>"unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0134s
main: -- add_index(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4", :unique=>true, :name=>"unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0014s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0008s
main: -- indexes(:packages_packages)
main:    -> 0.0137s
main: -- remove_index(:packages_packages, {:algorithm=>:concurrently, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian"})
main:    -> 0.0010s
main: == 20230317080137 AddUniquePackagesIndexWhenDebian: migrated (0.0476s) ========

Rollback:

main: == 20230317075852 AddTmpUniquePackagesIndexWhenDebian: migrating ==============
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0014s
main: -- index_exists?(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4 AND\n        created_at > TIMESTAMP WITH TIME ZONE '2023-03-23 08:49:11 UTC'", :unique=>true, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0185s
main: -- add_index(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4 AND\n        created_at > TIMESTAMP WITH TIME ZONE '2023-03-23 08:49:11 UTC'", :unique=>true, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0023s
main: == 20230317075852 AddTmpUniquePackagesIndexWhenDebian: migrated (0.0409s) =====
main: == 20230317080000 EnsureUniqueDebianPackages: migrating =======================
main: == 20230317080000 EnsureUniqueDebianPackages: migrated (0.0121s) ==============
main: == 20230317080137 AddUniquePackagesIndexWhenDebian: migrating =================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0015s
main: -- index_exists?(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4", :unique=>true, :name=>"unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0187s
main: -- add_index(:packages_packages, [:project_id, :name, :version], {:where=>"package_type = 9 AND status != 4", :unique=>true, :name=>"unique_packages_project_id_and_name_and_version_when_debian", :algorithm=>:concurrently})
main:    -> 0.0023s
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0017s
main: -- indexes(:packages_packages)
main:    -> 0.0201s
main: -- remove_index(:packages_packages, {:algorithm=>:concurrently, :name=>"tmp_unique_packages_project_id_and_name_and_version_when_debian"})
main:    -> 0.0016s
main: == 20230317080137 AddUniquePackagesIndexWhenDebian: migrated (0.0765s) ========
Edited by Mathieu Parent

Merge request reports