Refactor migration observers to have more information about the migration they are observing
The current way that migration observers are called makes them difficult to write effectively. Refactor them so that they are instantiated once per migration and know which migration they are observing before they observe it.
Definition of Done
-
Refactor lib/gitlab/database/migrations/instrumentation.rb
so that it creates an observer per migration, passing in the details of the migration being observed. -
Simplify lib/gitlab/database/migrations/observers/query_log.rb
andlib/gitlab/database/migrations/observers/query_details.rb
to not need temporary files now that the file name can be determined beforehand.
The following discussion from !64038 (merged) should be addressed:
-
@abrandl started a discussion: (+2 comments) @stomlinson Non blocking thought: I got the impression it could make sense to have stateful observers per migration. We wouldn't need to rename files, for example (similar to what we do in
QueryLog
). Alternatively, we can also start passing in the migration itself into the#before, #after
calls.I don't mind keeping it this way for now, but how about we keep watching out for this and see if we add more observers that would benefit from a little refactoring?