Manual:Hooks/LoadExtensionSchemaUpdates

Summary

 * 1) Create your hook as indicated below.  Each examples shows how to setup the hook function. However, if you have more than one schema update, you can put them in the same function (and it will use multiple SQL files).
 * 2) Make sure the hook has access to any necessary SQL files, which are usually located in an   directory.
 * 3) Format the SQL files correctly.  See the, and the corresponding , for some examples.
 * 4) From the command line run the   script to update your wiki’s database with your extension’s   hook. See the update.php manual for more information.

>= 1.25
was introduced in 1.25, and so the Hooks section of  should be used instead of. For example:

And in :

The code of the hook callback is the same as for earlier versions (see below).

To modify an existing field
To modify an existing field, put:

SQLite does not support some features of ALTER TABLE, such as renaming columns. Thus, work-arounds are necessary. See handling of  in Hooks.php and the accompanying files in the Echo extension.

To add a new index
To add a new index, put:

To add a new table
To add a new table, in the main file for your extension: The  file should contain the necessary   table definition.

To add a table and/or modify a field
If your extension has already added a table, but you need to modify a field in it for a new version, make the change in the sql file for the table (for people installing the extension after the change), then make a "patch" sql file to modify the field in the table (for people updating from an older version).

The  file should contain the necessary   statement to update old versions of the schema.

To add a new table
To add a new table, in the main file for your extension: The  file should contain the necessary   table definition.

To add a table and/or modify a field
If your extension has already added a table, but you need to modify a field in it for a new version, make the change in the sql file for the table (for people installing the extension after the change), then make a "patch" sql file to modify the field in the table (for people updating from an older version).

The  file should contain the necessary   statement to update old versions of the schema.

Note: Be very careful about the last member of the array being true. If you pass it an absolute path and nothing else, it will treat the path as relative to maintenance/archives and you will get all manner of errors.

<= 1.16 and >= 1.17 dual support
It is possible to provide support for both older versions of MediaWiki, and the current versions without much extra effort required

To add a new table
To add a new table, in the main file for your extension: The  file should contain the necessary   table definition. For an example, see the FlaggedRevs extension.

To add a table and/or modify a field
If your extension has already added a table, but you need to modify a field in it for a new version, make the change in the sql file for the table (for people installing the extension after the change), then make a "patch" sql file to modify the field in the table (for people updating from an older version).

The  file should contain the necessary   statement to update old versions of the schema.