Confirm database connection before running post migration
requested to merge gitlab-jh/jh-team/gitlab:confirm-database-connection-before-running-post-migration into master
What does this MR do and why?
Related to this note !111200 (comment 1272288120)
We need to add this new line
return unless Gitlab::Database.gitlab_schemas_for_connection(connection).include?(:gitlab_main)
to db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb
to fix the pipeline of JiHu.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
- Make sure you are running in decomposed database setup.
- Lock the legacy tables
rake gitlab:db:lock_writes
. - Run the CI migration
down
andup
onconfirm-database-connection-before-running-post-migration
branch. it should succeed.
➜ gitlab git:(confirm-database-connection-before-running-post-migration) be rake gitlab:db:lock_writes
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
➜ gitlab git:(confirm-database-connection-before-running-post-migration) be rails db:migrate:down:ci VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
ci: == 20221108045019 TruncateTimelineEventTagsTable: reverting ===================
ci: == 20221108045019 TruncateTimelineEventTagsTable: reverted (0.0004s) ==========
➜ gitlab git:(confirm-database-connection-before-running-post-migration) ✗ be rails db:migrate:up:ci VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
ci: == 20221108045019 TruncateTimelineEventTagsTable: migrating ===================
ci: == 20221108045019 TruncateTimelineEventTagsTable: migrated (0.0026s) ==========
➜ gitlab git:(confirm-database-connection-before-running-post-migration) ✗ be rails db:migrate:down:main VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
main: == 20221108045019 TruncateTimelineEventTagsTable: reverting ===================
main: == 20221108045019 TruncateTimelineEventTagsTable: reverted (0.0033s) ==========
➜ gitlab git:(confirm-database-connection-before-running-post-migration) ✗ be rails db:migrate:up:main VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
main: == 20221108045019 TruncateTimelineEventTagsTable: migrating ===================
main: -- execute("TRUNCATE TABLE incident_management_timeline_event_tags, incident_management_timeline_event_tag_links")
main: -> 0.0223s
main: == 20221108045019 TruncateTimelineEventTagsTable: migrated (0.0232s) ==========
- Run the CI migration
down
andup
onmaster
branch, it will fail.
➜ gitlab git:(master) be rails db:migrate:down:ci VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
ci: == 20221108045019 TruncateTimelineEventTagsTable: reverting ===================
ci: == 20221108045019 TruncateTimelineEventTagsTable: reverted (0.0006s) ==========
➜ gitlab git:(master) ✗ be rails db:migrate:up:ci VERSION=20221108045019
WARNING: This version of GitLab depends on gitlab-shell 14.17.0, but you're running 14.16.0. Please update gitlab-shell.
ci: == 20221108045019 TruncateTimelineEventTagsTable: migrating ===================
ci: -- execute("TRUNCATE TABLE incident_management_timeline_event_tags, incident_management_timeline_event_tag_links")
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
PG::SREModifyingSqlDataNotPermitted: ERROR: Table: "incident_management_timeline_event_tags" is write protected within this Gitlab database.
HINT: Make sure you are using the right database connection
CONTEXT: PL/pgSQL function gitlab_schema_prevent_write() line 4 at RAISE
/Users/zhzhang/working/gitlab-development-kit/gitlab/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb:7:in `up'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:33:in `block in exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/query_analyzer.rb:37:in `within'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:30:in `exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migrations/lock_retry_mixin.rb:36:in `ddl_transaction'
Caused by:
ActiveRecord::StatementInvalid: PG::SREModifyingSqlDataNotPermitted: ERROR: Table: "incident_management_timeline_event_tags" is write protected within this Gitlab database.
HINT: Make sure you are using the right database connection
CONTEXT: PL/pgSQL function gitlab_schema_prevent_write() line 4 at RAISE
/Users/zhzhang/working/gitlab-development-kit/gitlab/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb:7:in `up'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:33:in `block in exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/query_analyzer.rb:37:in `within'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:30:in `exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migrations/lock_retry_mixin.rb:36:in `ddl_transaction'
Caused by:
PG::SREModifyingSqlDataNotPermitted: ERROR: Table: "incident_management_timeline_event_tags" is write protected within this Gitlab database.
HINT: Make sure you are using the right database connection
CONTEXT: PL/pgSQL function gitlab_schema_prevent_write() line 4 at RAISE
/Users/zhzhang/working/gitlab-development-kit/gitlab/db/post_migrate/20221108045019_truncate_timeline_event_tags_table.rb:7:in `up'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:33:in `block in exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/query_analyzer.rb:37:in `within'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:30:in `exec_migration'
/Users/zhzhang/working/gitlab-development-kit/gitlab/lib/gitlab/database/migrations/lock_retry_mixin.rb:36:in `ddl_transaction'
Tasks: TOP => db:migrate:up:ci
(See full trace by running task with --trace)
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 Zehua Zhang