Page MenuHomePhabricator

Implement Doctrine DBAL Driver Connection wrapper for MW db connection
Closed, ResolvedPublic


When we want to use Doctrine DBAL, we do not want to create a direct connection to the database because then we will have to also deal with multiple environments and the load balancer on our own. So we thought we might reuse the connection that is created in MW core and pass it to Doctrine's DBAL connection.

In, we experimented on how we can create a wrapper of MW db connection that implements Doctrine DBAL Driver Connection and be used with Doctrine DBAL Connection instance.

Now we want to implement the driver connections for the different databases supported by mw/wikibase properly as a separate library, which then we can use in Wikibase project wherever needed.

Event Timeline

Wikibase Client also uses the TermIndex stuff, so I'm afraid we can't just put this into Wikibase Repository. Some options:

1. Dump the stuff in WikibaseLib garbage bin
Pro: least initial work
Con: minor increase of tech debt, further away from killing WikibaseLib
Con: not usable without loading Wikibase

2. Create dedicated library
Pro: max separation and reusability
Con: need to create library and have MW tests in it

3. Put in wikibase/term-store
Pro: partially reusable
Pro: encapsulation: MediaWikiTermStore that wraps DoctrineTermStore taking Database in constructor
Con: need to setup MW tests in library
Con: part of the library depends on MW (the rest would still work without and be tested without MW loaded)


After a bunch of consideration I moderately prefer "2. Create dedicated library". That approach does not clutter anything and it gives us a building block we can use in other projects, which I think is worth the small initial investment.

I'd go for 2 as well. Updated task description to reflect that ;)

alaa_wmde renamed this task from Implement Doctrine DBAL Driver Connection wrapper for mw context to Implement Doctrine DBAL Driver Connection wrapper for MW db connection.Apr 5 2019, 1:18 PM
alaa_wmde updated the task description. (Show Details)

Setting this up turned out to be easier than expected. The library has running tests on TravisCI and can transform Mysqli and SQLite (PDO) based MW Database objects.

Next steps:

  • Figure out if we need to support other database types (Which ones does Wikibase support?)
  • Improve access to the wrapped connections in MW core (currently done via Reflection)

Also: please review the code I wrote :)

Change 501119 had a related patch set uploaded (by Alaa Sarhan; owner: Alaa Sarhan):
[mediawiki/core@master] Allow getting db connection from Database

Change 501119 abandoned by Alaa Sarhan:
Allow getting db connection from Database