Kebijakan database MediaWiki

From mediawiki.org
This page is a translated version of the page MediaWiki database policy and the translation is 21% complete.

Halaman ini menjelaskan tentang kode database resmi untuk MediaWiki. Itu disetujui pada Desember 2019 melalui proses TechCom RFC per RFC T220056.

Kueri database

  • All new code that sends SQL queries from MediaWiki must not generate any warning under MariaDB/MySQL's strict mode (per RFC T112637).
    • WMF will be enabling MariaDB/MySQL's strict mode (T108255), which will be the default anyway in MySQL 5.7. Prior to this, code must be free of warnings.
    • Code that touches the database must be compatible with the following MySQL SQL modes:
      • TRADITIONAL (equivalent to STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER)
      • ONLY_FULL_GROUP_BY
  • Database code must be compatible with older versions of databases as listed in the MediaWiki installation requirements for database server. However, performance improvements that would only apply to the newest, supported versions (or its default or widely recommended defaults) should be favoured over those that apply only to unsupported releases.
  • Non-deterministic queries and unsafe statements for binlog should be avoided as they would return/write different results in a replication environment. The latter can be detected as warnings with the text "[Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT". Those include INSERT ... SELECT when using an auto_increment key, UPDATE ... LIMIT without an ORDER BY, and using non-deterministic functions like SYSDATE(). More information.

Perubahan skema

  • All new tables must have a primary key. When a candidate for primary key could not be created (for example, if all columns can be repeated), a separate auto_increment column, or other arbitrary field (depending on the case), must be added.
  • Primary keys, and fields that reference them, should be unsigned, in order to increase the maximum values.
  • All tables in MediaWiki core, and Wikimedia-deployed and MediaWiki-bundled extensions must be implemented using the abstract schema system, and new schema changes to them must be generated automatically.

Schema change compatibility

Schema changes must provide a path for upgrading from all releases from two LTS releases before onwards (see phab:T259771).

Path database

Jika Anda mengubah skema database, ikuti aturan berikut:

  • Update the installerUpdate includes/installer and add an appropriate SQL patch file to maintenance/archives/. The naming convention, if you're adding a field, is patch-{table}-{field}.sql. If you're removing a field, it is patch-drop-{table}-{field}.sql. If you're adding a table, it is patch-{table}.sql. Look at the commit history of includes/installer/(MySQL|Postgres|SQLite)Updater.php to find examples of how it is done. If you're adding a bunch of fields to the same table, make all those changes in one query in one patch file.
  • Make your schema change optionalAll schema changes must go through a period of being optional. Some examples:
    • Instead of changing the format of a column, create a new column, make all writes happen to the old and new column (if it exists), and deprecate use of the old column. Check if the new column exists before blindly assuming that it does. Only eliminate support for the old column after it is clear the schema migration has completed and there's no chance that we'll need to roll back to the old version of the software. If this doesn't seem feasible, send mail to Wikitech-l asking for advice.
    • You could set your new feature to only work if a config option is set to true, and set the option to false by default. Then the commit can be safely deployed before the schema change is made. To deploy your feature to the Wikimedia cluster, file a ticket in Phabricator in the relevant project with the #schema-change tag. Once you've confirmed the change has been made, you can remove the config option to enable your feature.
    • Note that this means your schema change should be optional in code - for Wikimedia deployments, it is expected that every wiki with the relevant database table(s) will have the schema change applied to them. If you need different schema for different wikis, then apply the change using an extension and creating new tables dependent on that extension.

Mungkin ada kasus di mana aturan buat perubahan skema Anda opsional akan menjadi penghalang dari perspektif kinerja atau logistik. Namun, perubahan skema seperti itu seharusnya jarang terjadi, dan harus memiliki dikusi yang menonjol di milis wikitech-l. Jika tidak mungkin mengubah skema menjadi opsional, tetap penting untuk menulis skrip untuk mengembalikan ke status pra-perubahan.

  • Search for input from a WMF Database AdministratorMediaWiki is deployed to Wikimedia websites every week, and it takes considerable planning to apply schema changes to MySQL-based sites the size of Wikipedia. As of Januari 2020 Jaime Crespo (jcrespo on LDAP, jynus on irc) and Manuel (Arostegui, marostegui) are the best people to add to database reviews. In most cases, input is just needed on the logistics of the change.
  • Test your changes on Beta - in particular, it is a common mistake to change indexes and column definitions that would result in different query plans. Try to test the generated queries' plan with tools such as EXPLAIN; not doing so could mean that, when scaled to production, queries that only take 1 second locally, they pileup on production when they receive much more traffic and have larger tables.


Note

Sejak Versi 1.36, MediaWiki hanya melakukan commit untuk mendukung pemutakhiran dari dua rilis LTS (lihat phab:T259771). Pemutakhiran dari versi MediaWiki yang lebih lama harus dilakukan dengan beberapa tahap. Jadi jika Anda ingin memutakhirkan ke 1.41 dari 1.34 atau sebelumnya, Anda harus memutakhirkan wiki 1.34 Anda ke 1.35 (atau 1.39) terlebih dahulu, kemudian dari 1.35 (atau 1.39) Anda bisa memutakhirkan ke 1.41.

Lihat juga