[RUN AS-IF-FOSS] Reference pages_deployments in pages_metadata
What does this MR do?
It will be used to access pages_deployment in the API and updated when new pages deployment is created.
Old pages deployment will removed ~15 minutes after to allow pages daemon to serve files from old deployment until it refreshes the cache.
I will create an association and use this reference in #228782 (closed). Wanted to keep this MR purely about database changes.
Migrate output
vlad @ gdk1 ➜ gitlab git:(245304-reference-pages_deployments-in-pages_metadata) ✗ ./bin/rails db:migrate
== 20200921130028 AddPagesDeploymentIdToPagesMetadata: migrating ==============
-- add_column(:project_pages_metadata, :pages_deployment_id, :bigint)
-> 0.0022s
== 20200921130028 AddPagesDeploymentIdToPagesMetadata: migrated (0.0023s) =====
== 20200921131313 AddForeignKeyToPagesDeploymentIdInProjectPagesMetadata: migrating
-- transaction_open?()
-> 0.0000s
-- index_exists?(:project_pages_metadata, :pages_deployment_id, {:name=>"idx_project_pages_metadata_on_pages_deployment_id", :algorithm=>:concurrently})
-> 0.0144s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index(:project_pages_metadata, :pages_deployment_id, {:name=>"idx_project_pages_metadata_on_pages_deployment_id", :algorithm=>:concurrently})
-> 0.0070s
-- execute("RESET ALL")
-> 0.0003s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:project_pages_metadata)
-> 0.0059s
-- execute("ALTER TABLE project_pages_metadata\nADD CONSTRAINT fk_0fd5b22688\nFOREIGN KEY (pages_deployment_id)\nREFERENCES pages_deployments (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0022s
-- execute("ALTER TABLE project_pages_metadata VALIDATE CONSTRAINT fk_0fd5b22688;")
-> 0.0025s
== 20200921131313 AddForeignKeyToPagesDeploymentIdInProjectPagesMetadata: migrated (0.0434s)
vlad @ gdk1 ➜ gitlab git:(245304-reference-pages_deployments-in-pages_metadata) ✗ ./bin/rails db:rollback STEP=2
== 20200921131313 AddForeignKeyToPagesDeploymentIdInProjectPagesMetadata: reverting
-- foreign_keys(:project_pages_metadata)
-> 0.0191s
-- remove_foreign_key(:project_pages_metadata, {:column=>:pages_deployment_id})
-> 0.0083s
-- transaction_open?()
-> 0.0000s
-- indexes(:project_pages_metadata)
-> 0.0053s
-- execute("SET statement_timeout TO 0")
-> 0.0002s
-- remove_index(:project_pages_metadata, {:algorithm=>:concurrently, :name=>"idx_project_pages_metadata_on_pages_deployment_id"})
-> 0.0039s
-- execute("RESET ALL")
-> 0.0002s
== 20200921131313 AddForeignKeyToPagesDeploymentIdInProjectPagesMetadata: reverted (0.0384s)
== 20200921130028 AddPagesDeploymentIdToPagesMetadata: reverting ==============
-- remove_column(:project_pages_metadata, :pages_deployment_id, :bigint)
-> 0.0012s
== 20200921130028 AddPagesDeploymentIdToPagesMetadata: reverted (0.0027s) =====
Index Creation
The new index is created in 25 seconds in #datbase-lab
, so it is safe to add it with a regular migration.
exec CREATE INDEX index_project_pages_metadata_on_pages_deployment_id ON project_pages_metadata USING btree (pages_deployment_id);
The query has been executed. Duration: 25.234 s
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Closes #245304 (closed)
Edited by Vladimir Shushlin