Move database partitioning code from initializers to module for reusing
What does this MR do and why?
Move database partitioning code from initializers to module for reusing.
This is trying to resolve the issue in gitlab-jh/gitlab#356 (comment 728224686)
Where we have an additional initialize (jh/config/initializers/postgres_partitioning.rb
) will register another partitioned model, however, Partitioning.sync_partitions
isn't called again with that in mind.
By extracting this code into a method, we can reuse it there. The merge request is in gitlab-jh/gitlab!172 (merged)
How to set up and validate locally
-
git checkout v14.4.0
orgit checkout v14.4.0-ee
- Note this is destructive to local database:
bundle exec rake db:drop db:create db:structure:load db:migrate
-
git checkout main-jh
(the branch can be fetched from https://gitlab.com/gitlab-jh/gitlab/tree/main-jh) bundle config set --local gemfile jh/Gemfile
bundle install
bundle exec rake db:migrate
- Notice that
db/structure.sql
is changed. - Running this will restore that:
rake db:structure:dump
because it'll runGitlab::Database::Partitioning.sync_partitions
before dumping the schema.
Here's the JiHu merge request to show that it's fixing the CI job db:check-schema
over there: gitlab-jh/gitlab!172 (merged)
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 Lin Jen-Shin