MediaWiki
REL1_39
generateSchemaSql.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
GenerateSchemaSql
extends
SchemaMaintenance
{
37
public
function
__construct
() {
38
parent::__construct();
39
$this->
addDescription
(
'Build SQL files from abstract JSON files'
);
40
$this->scriptName =
'generateSchemaSql.php'
;
41
}
42
43
protected
function
generateSchema
(
string
$platform, array $schema ): string {
44
$schemaBuilder = ( new
DoctrineSchemaBuilderFactory
() )->getSchemaBuilder( $platform );
45
46
foreach
( $schema as $table ) {
47
$schemaBuilder->addTable( $table );
48
}
49
$sql =
''
;
50
51
$tables = $schemaBuilder->getSql();
52
if
( $tables !== [] ) {
53
// Temporary
54
$sql .= implode(
";\n\n"
, $tables ) .
';'
;
55
$sql = (
new
SqlFormatter(
new
NullHighlighter() ) )->format( $sql );
56
}
57
58
// Postgres hacks
59
if
( $platform ===
'postgres'
) {
60
// FIXME: Fix a lot of weird formatting issues caused by
61
// presence of partial index's WHERE clause, this should probably
62
// be done in some better way, but for now this can work temporarily
63
$sql = str_replace(
64
[
"WHERE\n "
,
"\n /*_*/\n "
,
" "
,
" );"
,
"KEY(\n "
],
65
[
"WHERE"
,
' '
,
" "
,
');'
,
"KEY(\n "
],
66
$sql
67
);
68
}
69
70
// Until the linting issue is resolved
71
// https://github.com/doctrine/sql-formatter/issues/53
72
$sql = str_replace(
"\n/*_*/\n"
,
" /*_*/"
, $sql );
73
$sql = str_replace(
"; CREATE "
,
";\n\nCREATE "
, $sql );
74
$sql = str_replace(
";\n\nCREATE TABLE "
,
";\n\n\nCREATE TABLE "
, $sql );
75
$sql = str_replace(
76
"\n"
.
'/*$wgDBTableOptions*/'
.
";"
,
77
' /*$wgDBTableOptions*/;'
,
78
$sql
79
);
80
$sql = str_replace(
81
"\n"
.
'/*$wgDBTableOptions*/'
.
"\n;"
,
82
' /*$wgDBTableOptions*/;'
,
83
$sql
84
);
85
$sql .=
"\n"
;
86
87
return
$sql;
88
}
89
90
}
91
92
$maintClass
= GenerateSchemaSql::class;
93
require_once RUN_MAINTENANCE_IF_MAIN;
GenerateSchemaSql
Maintenance script to generate schema from abstract json files.
Definition
generateSchemaSql.php:36
GenerateSchemaSql\generateSchema
generateSchema(string $platform, array $schema)
Definition
generateSchemaSql.php:43
GenerateSchemaSql\__construct
__construct()
Default constructor.
Definition
generateSchemaSql.php:37
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:319
SchemaMaintenance
Definition
SchemaMaintenance.php:30
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory
@experimental
Definition
DoctrineSchemaBuilderFactory.php:14
$maintClass
$maintClass
Definition
generateSchemaSql.php:92
maintenance
generateSchemaSql.php
Generated on Mon Nov 4 2024 07:25:05 for MediaWiki by
1.10.0