MediaWiki
REL1_39
generateSchemaChangeSql.php
Go to the documentation of this file.
1
<?php
2
25
use Doctrine\SqlFormatter\NullHighlighter;
26
use Doctrine\SqlFormatter\SqlFormatter;
27
use
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory
;
28
29
require_once __DIR__ .
'/includes/SchemaMaintenance.php'
;
30
36
class
GenerateSchemaChangeSql
extends
SchemaMaintenance
{
37
public
function
__construct
() {
38
parent::__construct();
39
$this->
addDescription
(
'Build SQL files for schema changes from abstract JSON files'
);
40
$this->scriptName =
'generateSchemaChangeSql.php'
;
41
}
42
43
protected
function
generateSchema
(
string
$platform, array $schema ): string {
44
$schemaChangeBuilder = ( new
DoctrineSchemaBuilderFactory
() )->getSchemaChangeBuilder( $platform );
45
46
$schemaChangeSqls = $schemaChangeBuilder->getSchemaChangeSql( $schema );
47
48
$sql =
''
;
49
50
if
( $schemaChangeSqls !== [] ) {
51
// Temporary
52
$sql .= implode(
";\n\n"
, $schemaChangeSqls ) .
';'
;
53
$sql = (
new
SqlFormatter(
new
NullHighlighter() ) )->format( $sql );
54
}
else
{
55
$this->
fatalError
(
'No schema changes detected!'
);
56
}
57
58
// Until the linting issue is resolved
59
// https://github.com/doctrine/sql-formatter/issues/53
60
$sql = str_replace(
"\n/*_*/\n"
,
" /*_*/"
, $sql );
61
$sql = str_replace(
"; "
,
";\n"
, $sql );
62
$sql = preg_replace(
"/\n+? +?/"
,
' '
, $sql );
63
$sql = str_replace(
"/*_*/ "
,
"/*_*/"
, $sql );
64
65
// Sqlite hacks
66
if
( $platform ===
'sqlite'
) {
67
// Doctrine prepends __temp__ to the table name and we set the table with the schema prefix causing invalid
68
// sqlite.
69
$sql = preg_replace(
'/__temp__\s*\/\*_\*\//'
,
'/*_*/__temp__'
, $sql );
70
}
71
72
return
$sql;
73
}
74
75
}
76
77
$maintClass
= GenerateSchemaChangeSql::class;
78
require_once RUN_MAINTENANCE_IF_MAIN;
GenerateSchemaChangeSql
Maintenance script to generate schema from abstract json files.
Definition
generateSchemaChangeSql.php:36
GenerateSchemaChangeSql\__construct
__construct()
Default constructor.
Definition
generateSchemaChangeSql.php:37
GenerateSchemaChangeSql\generateSchema
generateSchema(string $platform, array $schema)
Definition
generateSchemaChangeSql.php:43
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:319
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition
Maintenance.php:497
SchemaMaintenance
Definition
SchemaMaintenance.php:30
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory
@experimental
Definition
DoctrineSchemaBuilderFactory.php:14
$maintClass
$maintClass
Definition
generateSchemaChangeSql.php:77
maintenance
generateSchemaChangeSql.php
Generated on Mon Nov 25 2024 06:57:43 for MediaWiki by
1.10.0