diff options
-rw-r--r-- | includes/libs/rdbms/database/DoctrineSchemaBuilder.php | 15 | ||||
-rw-r--r-- | maintenance/generateSchemaSql.php | 9 | ||||
-rw-r--r-- | tests/phpunit/data/db/mysql/tables.sql | 2 |
3 files changed, 20 insertions, 6 deletions
diff --git a/includes/libs/rdbms/database/DoctrineSchemaBuilder.php b/includes/libs/rdbms/database/DoctrineSchemaBuilder.php index 9e7352f6e677..cc82aa48dffa 100644 --- a/includes/libs/rdbms/database/DoctrineSchemaBuilder.php +++ b/includes/libs/rdbms/database/DoctrineSchemaBuilder.php @@ -13,13 +13,21 @@ class DoctrineSchemaBuilder implements SchemaBuilder { private $schema; private $platform; - const TABLE_PREFIX = '/*_*/'; + public const TABLE_PREFIX = '/*_*/'; + /** + * A builder object that take abstract schema definition and produces sql to create the tables. + * + * @param AbstractPlatform $platform A Doctrine Platform object, Can be Mysql, Sqlite, etc. + */ public function __construct( AbstractPlatform $platform ) { $this->schema = new Schema(); $this->platform = $platform; } + /** + * @inheritDoc + */ public function addTable( array $schema ) { $table = $this->schema->createTable( self::TABLE_PREFIX . $schema['name'] ); foreach ( $schema['columns'] as $column ) { @@ -33,9 +41,12 @@ class DoctrineSchemaBuilder implements SchemaBuilder { } } $table->setPrimaryKey( $schema['pk'] ); - $table->addOption( 'table_options', '' ); + $table->addOption( 'table_options', '/*$wgDBTableOptions*/' ); } + /** + * @inheritDoc + */ public function getSql() { return $this->schema->toSql( $this->platform ); } diff --git a/maintenance/generateSchemaSql.php b/maintenance/generateSchemaSql.php index 5caaf64aac64..1ce4a13441b7 100644 --- a/maintenance/generateSchemaSql.php +++ b/maintenance/generateSchemaSql.php @@ -57,8 +57,8 @@ class GenerateSchemaSql extends Maintenance { } public function execute() { - $jsonFile = $this->getOption( 'json', 'tables.json' ); - $sqlFile = $this->getOption( 'sql', 'tables-generated.sql' ); + $jsonFile = $this->getOption( 'json', __DIR__ . '/tables.json' ); + $sqlFile = $this->getOption( 'sql', __DIR__ . '/tables-generated.sql' ); $abstractSchema = json_decode( file_get_contents( $jsonFile ), true ); $schemaBuilder = ( new DoctrineSchemaBuilderFactory() )->getSchemaBuilder( $this->getOption( 'type', 'mysql' ) @@ -66,7 +66,10 @@ class GenerateSchemaSql extends Maintenance { foreach ( $abstractSchema as $table ) { $schemaBuilder->addTable( $table ); } - file_put_contents( $sqlFile, $schemaBuilder->getSql() ); + $sql = "-- This file is automatically generated using maintenance/generateSchemaSql.php.\n" . + "-- Do not modify this file directly.\n" . + "-- See https://www.mediawiki.org/wiki/Manual:Schema_changes\n"; + file_put_contents( $sqlFile, $sql . implode( ";\n\n", $schemaBuilder->getSql() ) . ';' ); } } diff --git a/tests/phpunit/data/db/mysql/tables.sql b/tests/phpunit/data/db/mysql/tables.sql index e36e77b9545a..89ee77363acd 100644 --- a/tests/phpunit/data/db/mysql/tables.sql +++ b/tests/phpunit/data/db/mysql/tables.sql @@ -1 +1 @@ -CREATE TABLE /*_*/actor (actor_id BIGINT UNSIGNED NOT NULL, actor_user INT UNSIGNED NOT NULL, actor_name VARCHAR(255) NOT NULL, UNIQUE INDEX actor_user (actor_user), UNIQUE INDEX actor_name (actor_name), PRIMARY KEY(actor_id)) +CREATE TABLE /*_*/actor (actor_id BIGINT UNSIGNED NOT NULL, actor_user INT UNSIGNED NOT NULL, actor_name VARCHAR(255) NOT NULL, UNIQUE INDEX actor_user (actor_user), UNIQUE INDEX actor_name (actor_name), PRIMARY KEY(actor_id)) /*$wgDBTableOptions*/ |