Exclude migration models from DB dictionary
What does this MR do and why?
In order to decouple migrations from the application code we define AR models inside migration when needed (sub-classes of MigrationRecord
). These are usually not included in the DB dictionary, as the files are not loaded, unless it happens the dictionary is generated after db:migrate
that executed migration defining such model. In this case we end up with the model added to the classes list for the table.
This MR adds additional filter in order to reject such model classes.
Screenshots or screen recordings
How to set up and validate locally
- Create migration
# db/migrate/20230303000404_test_with_model.rb
like:class TestWithModel < Gitlab::Database::Migration[2.1] class Project < MigrationRecord self.table_name = 'projects' end def change end end
- When on
master
executedb:migrate
. There should be a diff like:diff --git a/db/docs/projects.yml b/db/docs/projects.yml index 0b7dbbe2127c..82cb3c64a4f4 100644 --- a/db/docs/projects.yml +++ b/db/docs/projects.yml @@ -2,6 +2,7 @@ table_name: projects classes: - Project +- TestWithModel::Project feature_categories: - projects description: Stores project records
- When on this branch execute
db:migrate
. There should no change todb/docs/projects.yml
.
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.