2020-01-18 19:10:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a JSON abstract schema to a schema file in the given DBMS type
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use Wikimedia\Rdbms\DoctrineSchemaBuilderFactory;
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2022-02-11 10:24:54 +00:00
|
|
|
require_once __DIR__ . '/includes/SchemaMaintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2020-01-18 19:10:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maintenance script to generate schema from abstract json files.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2022-02-11 10:24:54 +00:00
|
|
|
class GenerateSchemaSql extends SchemaMaintenance {
|
2020-01-18 19:10:13 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addDescription( 'Build SQL files from abstract JSON files' );
|
2022-02-11 10:24:54 +00:00
|
|
|
$this->scriptName = 'generateSchemaSql.php';
|
2020-01-18 19:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-11 10:24:54 +00:00
|
|
|
protected function generateSchema( string $platform, array $schema ): string {
|
2020-11-12 15:43:44 +00:00
|
|
|
$schemaBuilder = ( new DoctrineSchemaBuilderFactory() )->getSchemaBuilder( $platform );
|
|
|
|
|
|
2022-02-11 10:24:54 +00:00
|
|
|
foreach ( $schema as $table ) {
|
2020-01-18 19:10:13 +00:00
|
|
|
$schemaBuilder->addTable( $table );
|
|
|
|
|
}
|
2023-07-21 03:33:15 +00:00
|
|
|
$tableSqls = $schemaBuilder->getSql();
|
2020-05-09 11:54:54 +00:00
|
|
|
|
2023-07-21 03:33:15 +00:00
|
|
|
$sql = $this->cleanupSqlArray( $platform, $tableSqls );
|
2020-05-09 11:54:54 +00:00
|
|
|
|
2022-02-11 10:24:54 +00:00
|
|
|
return $sql;
|
2020-01-18 19:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2020-01-18 19:10:13 +00:00
|
|
|
$maintClass = GenerateSchemaSql::class;
|
|
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|