Skip to content
代码片段 群组 项目
提交 3d65302a 编辑于 作者: Dmitry Gruzd's avatar Dmitry Gruzd
浏览文件

Merge branch 'jp-embedding-helper' into 'master'

Add support for embedding to migration helpers

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138143



Merged-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Approved-by: default avatarNicolas Dular <ndular@gitlab.com>
Approved-by: default avatarDmitry Gruzd <dgruzd@gitlab.com>
Reviewed-by: default avatarNicolas Dular <ndular@gitlab.com>
Co-authored-by: default avatarJan Provaznik <jprovaznik@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -12,8 +12,8 @@ def reset_column_information(klass) ...@@ -12,8 +12,8 @@ def reset_column_information(klass)
override :active_record_base override :active_record_base
def active_record_base(...) def active_record_base(...)
if geo_migration? if custom_migration?
::Geo::TrackingBase db_base_model
else else
super super
end end
...@@ -21,8 +21,8 @@ def active_record_base(...) ...@@ -21,8 +21,8 @@ def active_record_base(...)
override :migrations_paths override :migrations_paths
def migrations_paths def migrations_paths
if geo_migration? if custom_migration?
geo_db_config.configuration_hash[:migrations_paths] db_base_model.connection_db_config.configuration_hash[:migrations_paths]
else else
super super
end end
...@@ -44,18 +44,18 @@ def migrate! ...@@ -44,18 +44,18 @@ def migrate!
end end
def with_db_config(&block) def with_db_config(&block)
if geo_migration? if custom_migration?
with_added_geo_connection { yield } with_custom_connection { yield }
else else
yield yield
end end
end end
def with_added_geo_connection def with_custom_connection
with_reestablished_active_record_base(reconnect: true) do with_reestablished_active_record_base(reconnect: true) do
reconfigure_db_connection( reconfigure_db_connection(
name: :geo, name: geo_migration? ? :geo : :embedding,
config_model: Geo::TrackingBase, config_model: db_base_model,
model: ActiveRecord::Base model: ActiveRecord::Base
) )
...@@ -63,12 +63,26 @@ def with_added_geo_connection ...@@ -63,12 +63,26 @@ def with_added_geo_connection
end end
end end
def custom_migration?
geo_migration? || embedding_migration?
end
def geo_migration? def geo_migration?
self.class.metadata[:geo] self.class.metadata[:geo]
end end
def geo_db_config def embedding_migration?
Geo::TrackingBase.connection_db_config self.class.metadata[:embedding]
end
def db_base_model
if geo_migration?
Geo::TrackingBase
elsif embedding_migration?
::Embedding::ApplicationRecord
else
raise "unknown database migration"
end
end end
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册