Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,763
    • Issues 44,763
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,330
    • Merge requests 1,330
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #363491
Closed
Open
Issue created May 25, 2022 by Kamil Trzciński@ayufan🔴Maintainer

Enable Geo migrations to use `Migration[2.0]`

Following up: #358430 (comment 958870586)

Problem

@ayufan It seems that Migration\[2.0\] does not work with Geo migrations. See:

❯ be rails g geo_migration CreateFoo
      create  ee/db/geo/migrate/20220523223729_create_foo.rb
❯ be rails db:migrate:geo
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

key not found: "geo"
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:212:in `gitlab_schemas_for_connection'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:57:in `allowed_schemas_for_connection'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:53:in `unmatched_schemas'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:25:in `migrate'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:119:in `block in write_using_load_balancer'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:112:in `block in read_write'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:118:in `write_using_load_balancer'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:70:in `transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:295:in `block in transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:294:in `transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migrations/lock_retry_mixin.rb:36:in `ddl_transaction'

Caused by:
KeyError: key not found: "geo"
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:212:in `gitlab_schemas_for_connection'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:57:in `allowed_schemas_for_connection'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:53:in `unmatched_schemas'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:25:in `migrate'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:119:in `block in write_using_load_balancer'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:112:in `block in read_write'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:118:in `write_using_load_balancer'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:70:in `transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:295:in `block in transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database.rb:294:in `transaction'
/Users/dbalexandre/Sandbox/gdk-geo/gitlab/lib/gitlab/database/migrations/lock_retry_mixin.rb:36:in `ddl_transaction'
Tasks: TOP => db:migrate:geo
(See full trace by running task with --trace)

Falling back to Migration\[1.0\]:

❯ be rails db:migrate:geo
== 20220523223729 CreateFoo: migrating ========================================
-- create_table(:foos, {})
   -> 0.0177s
== 20220523223729 CreateFoo: migrated (0.0177s) ===============================

Solution

Geo should implement gitlab_geo and adds its Geo::TrackingBase to self.database_base_models schema in order to use Migration[2.0]. Till that moment Geo should continue using Migration[1.0] as it is safe to do so with the following caveats that are unchanged by Migration[2.0]:

  • background migrations can only work in track_jobs: false mode since Geo database does not have tracking tables
  • batched background migrations are not supported since there's no tracking jobs

Workaround

Geo should continue using Migration[1.0] till the gitlab_geo is supported. It will be exempt today from being validated about using Migration[2.0]. This will require developer to manually amend migration file to change from [2.0] to [1.0] due to migration defaults being 2.0.

Related

  • Introduce :gitlab_geo schema for Geo tracking D... (#358422 - closed)
  • Introduce :gitlab_geo schema for Geo tracking DB (!85842 - merged)
  • Decomposition: Support for many databases (&6103 - closed)
  • Rollout of `Gitlab::Database::Migration[2.0]` w... (#358430 - closed)
Assignee
Assign to
Time tracking