Skip to content

Refactor Database::Connection into separate types

Yorick Peterse requested to merge yorick/refactor-database-connection-class into master

What does this MR do and why?

Gitlab::Database::Connection was a kitchen sink type of class: it had methods for obtaining database information (e.g. the database name), running WAL related queries, querying the status of transactions, and more.

This commit splits this class into separate types. For example, reflection related methods are now located in Gitlab::Database::Reflection. Transaction related methods are moved into the Transactions module. The method to get a WAL diff has been moved into the LoadBalancer class.

With this also changes the use of these methods. For example, instead of this:

Gitlab::Database.main.cached_column_exists?(:users, :id)

You now write this:

Users.database.cached_column_exists?(:id)

Apart from being shorter in many cases, it also decouples the code using these methods from the main database. This makes it easier to support multiple databases over time.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Yorick Peterse

Merge request reports