Mailing List Archive

Request for feedback: Two changes related to databases in MediaWiki
Hello,
Two changes is being made on MediaWiki databases:

*First:*
We are reworking how extensions manage their database schema. The idea is
to basically deprecate LoadExtensionSchemaUpdates hook[1] and replace it
with structured values in extension.json.

This is needed to avoid arbitrary php code execution during database update
which can cause problems and was a contributing factor in one of our major
outages [2]. The other reason for this change is to be able to wire
abstract schema of extensions to core so it can be tested in CI (for
example for having a valid json, having prefixes set correctly, etc.) You
can see a POC of that in [3]

Given that once the change is merged to core, breaking changs to extension
registry schema would require a lot of work (updating the maniphest version
and so on), it's better to get it right before merge.

I have proposed something like [4]. For any feedback on this, please go to
https://phabricator.wikimedia.org/T237839,

*Second:*
We are working to provide a replacement for raw SQL for query conditions.
When the query condition is exact equality condition (e.g. rev_id = 123),
you don't need to provide raw SQL but for most other cases you need to
either provide it or build it via IDatabase methods. For example:
'rev_timestamp > ' . $db->addQuotes( $db->timestamp( $since ) ). You can
see an example of this in [5] (being changed to something much better via a
newly introduced method).

This is not optimal and not very developer friendly, to solve that, we are
proposing to have something like ExpressionBuilder::greater(
'rev_timestamp', $db->timestamp( $since ) ) supported in
SelectQueryBuilder::where().

You can see the POC in [6]. For any feedback on this please go to
https://phabricator.wikimedia.org/T210206

[1] https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates
[2]
https://wikitech.wikimedia.org/wiki/Incidents/2020-04-07_Wikidata%27s_wb_items_per_site_table_dropped
[3]
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/816262/10/tests/phpunit/structure/AbstractSchemaValidationTest.php
[4] https://phabricator.wikimedia.org/T237839#8268173
[5]
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/832625/6/includes/api/ApiQueryDeletedrevs.php
[6] https://gerrit.wikimedia.org/r/c/mediawiki/core/+/841940/

Thank you
--
*Amir Sarabadani (he/him)*
Staff Database Architect
Wikimedia Foundation <https://wikimediafoundation.org/>