Jump to content
MediaWiki

Manual:generateSchemaSql.php

From mediawiki.org
Languages:
MediaWiki version:
≥ 1.35
MediaWiki file: generateSchemaSql.php
Location: maintenance/
Source code: master1.43.11.42.61.39.12
Classes: GenerateSchemaSql

Details

[edit ]

This maintenance script builds SQL files from abstract JSON files. The feature to generate SQL files from abstract JSON file was introduced in MediaWiki 1.35 by RFC: T191231. MediaWiki uses Doctrine DBAL library to generate DDL files from the abstractions. Read more at Manual:Schema changes.

Options/Arguments

[edit ]
Option Description Required? Default value
--json Path to the json file Optional tables.json
--sql Path to output Optional tables-generated.sql
--type Output database type
Can be either 'mysql', 'sqlite', or 'postgres'
Optional mysql

Usage

[edit ]
phpmaintenance/run.phpgenerateSchemaSql[OPTION]...
In MediaWiki version 1.39.12 and earlier, you must invoke maintenance scripts using php maintenance/scriptName.php instead of php maintenance/run.php scriptName.

Generating MySQL file from actorTable.json

[edit ]
actorTable.json
[
{
"name":"actor",
"comment":"The \"actor\" table associates user names or IP addresses with integers for the benefit of other tables that need to refer to either logged-in or logged-out users. If something can only ever be done by logged-in users, it can refer to the user table directly.",
"columns":[
{
"name":"actor_id",
"comment":"Unique ID to identify each actor",
"type":"bigint",
"options":{"unsigned":true,"notnull":true,"autoincrement":true}
},
{
"name":"actor_user",
"comment":"Key to user.user_id, or NULL for anonymous edits",
"type":"integer",
"options":{"unsigned":true,"notnull":false}
},
{
"name":"actor_name",
"comment":"Text username or IP address",
"type":"binary",
"options":{"length":255,"notnull":true}
}
],
"indexes":[
{"name":"actor_user","columns":["actor_user"],"unique":true},
{"name":"actor_name","columns":["actor_name"],"unique":true}
],
"pk":["actor_id"]
}
]
Terminal
$ php maintenance/run.php generateSchemaSql --json actorTable.json --sql actorTable.sql

Output:

-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: actorTable.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATETABLE/*_*/actor(
actor_idBIGINTUNSIGNEDAUTO_INCREMENTNOTNULL,
actor_userINTUNSIGNEDDEFAULTNULL,
actor_nameVARBINARY(255)NOTNULL,
UNIQUEINDEXactor_user(actor_user),
UNIQUEINDEXactor_name(actor_name),
PRIMARYKEY(actor_id)
)/*$wgDBTableOptions*/;

Generating SQLite file from actorTable.json

[edit ]
Terminal
$ php maintenance/run.php generateSchemaSql --json actorTable.json --sql actorTable.sqlite --type sqlite

Output:

-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: a.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATETABLE/*_*/actor(
actor_idINTEGERPRIMARYKEYAUTOINCREMENTNOTNULL,
actor_userINTEGERUNSIGNEDDEFAULTNULL,
actor_nameBLOBNOTNULL
);

CREATEUNIQUEINDEXactor_userON/*_*/actor(actor_user);

CREATEUNIQUEINDEXactor_nameON/*_*/actor(actor_name);

See also

[edit ]

AltStyle によって変換されたページ (->オリジナル) /