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
.