Skip to content

Add PagesDeployment#deleted_at field

What does this MR do and why?

Add PagesDeployment#deleted_at field

Currently when a new PagesDeployment is created, we add its id to ProjectPagesMetadatum. This step is required as the new deployment might take a while to be uploaded to the Object Storage, therefore, instead of only replacing the current deployment for the project, we create a new one to avoid race conditions.

With the work to introduce Gitlab Pages Multiple Versions, a project now have to support multiple PagesDeployment at the same time. For this reason, instead of using ProjectPagesMetadatum#pages_deployment_id to identify valid deployment, we're introducing a PagesDeployment#deleted_at field.

The PagesDeployment#deleted_at is used to signalize when a new deployment for a project was created, marking old ones with deleted_at date. This will be used to clean old deployments and filter for active deployments.

In the near future it'll differentiate when a new deployment for a given project and path_prefix was created.

Related to:

Changelog: changed

FYI: the next MR will make further usage of this new field - Draft: Prepare Pages deployment to Multiple Ver... (!130871 - closed)

Migrations

bundle exec rails db:migrate:up:main VERSION=20230913171402
main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 67966
main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 67966
bundle exec rails db:migrate:up:ci VERSION=20230913171402
ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 68824
ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 68824
bundle exec rails db:migrate:up:main VERSION=20230913171403
main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 69617
main: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: migrating ================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0562s
main: -- index_exists?(:pages_deployments, [:id, :project_id, :path_prefix], {:where=>"deleted_at IS NULL", :name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
main:    -> 0.0024s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- add_index(:pages_deployments, [:id, :project_id, :path_prefix], {:where=>"deleted_at IS NULL", :name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
main:    -> 0.0020s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: migrated (0.0724s) =======

main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 69617
bundle exec rails db:migrate:up:ci VERSION=20230913171403
ci: == [advisory_lock_connection] object_id: 226840, pg_backend_pid: 70434
ci: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: migrating ================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0563s
ci: -- index_exists?(:pages_deployments, [:id, :project_id, :path_prefix], {:where=>"deleted_at IS NULL", :name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
ci:    -> 0.0027s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- add_index(:pages_deployments, [:id, :project_id, :path_prefix], {:where=>"deleted_at IS NULL", :name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
ci:    -> 0.0024s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0004s
ci: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: migrated (0.0808s) =======

ci: == [advisory_lock_connection] object_id: 226840, pg_backend_pid: 70434
bundle exec rails db:migrate:down:main VERSION=20230913171403
main: == [advisory_lock_connection] object_id: 226840, pg_backend_pid: 72837
main: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: reverting ================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0564s
main: -- index_exists?(:pages_deployments, [:id, :project_id, :path_prefix], {:name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
main:    -> 0.0028s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0002s
main: -- remove_index(:pages_deployments, {:name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently, :column=>[:id, :project_id, :path_prefix]})
main:    -> 0.0034s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: reverted (0.0735s) =======

main: == [advisory_lock_connection] object_id: 226840, pg_backend_pid: 72837
bundle exec rails db:migrate:down:ci VERSION=20230913171403
ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 73647
ci: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: reverting ================
ci: -- transaction_open?()
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0522s
ci: -- index_exists?(:pages_deployments, [:id, :project_id, :path_prefix], {:name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently})
ci:    -> 0.0036s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0002s
ci: -- remove_index(:pages_deployments, {:name=>"pages_deployments_deleted_at_index", :algorithm=>:concurrently, :column=>[:id, :project_id, :path_prefix]})
ci:    -> 0.0041s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0002s
ci: == 20230913171403 AddPagesDeploymentsDeletedAtIndex: reverted (0.0770s) =======

ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 73647
bundle exec rails db:migrate:down:main VERSION=20230913171402
main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 74443
main: == 20230913171402 AddDeletedAtToPagesDeployments: reverting ===================
main: -- remove_column(:pages_deployments, :deleted_at, :datetime_with_timezone, {:null=>true})
main:    -> 0.0017s
main: == 20230913171402 AddDeletedAtToPagesDeployments: reverted (0.0059s) ==========

main: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 74443
bundle exec rails db:migrate:down:ci VERSION=20230913171402
ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 75245
ci: == 20230913171402 AddDeletedAtToPagesDeployments: reverting ===================
ci: -- remove_column(:pages_deployments, :deleted_at, :datetime_with_timezone, {:null=>true})
ci:    -> 0.0011s
ci: == 20230913171402 AddDeletedAtToPagesDeployments: reverted (0.0097s) ==========

ci: == [advisory_lock_connection] object_id: 226780, pg_backend_pid: 75245

Explain: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/22230/commands/71872

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.

Edited by Kassio Borges

Merge request reports