Commit graph

8 commits

Author SHA1 Message Date
Gergő Tisza
ef338f3d56
db: Allow describing table creation via abstract schema change
Allow the 'before' field of an abstract schema change to be empty,
to describe a schema change that adds a new schema.

Merge the SQL logic, as generateSchemaChangeSql.php did not have
any cleanup for CREATE commands. Make some replacements simpler
and/or more robust. There are some other minor functional changes:
some double spaces are replaced by single spaces, ALTER is
formatted more nicely.

Change-Id: Ib2f60b492ced8ffe7bd6119f590c81f6a0ea9282
2023-10-10 20:06:53 -07:00
Alexander Vorwerk
bd1aa92f46 maintenance: Allow running schema maintenance without local settings
Change-Id: I2735972d572b91cd30dd28ced9bcc52587b5a8c0
2023-06-27 00:24:13 +02:00
Umherirrender
eb159d8f5a Remove unneeded initalize of local variables
The variables are set conditional later, but all condition branches set
it or the variable is not used outside that scope

Change-Id: Ic9612915db507028ad4733a061d3ce9be3babfb6
2022-09-21 21:29:21 +02:00
Umherirrender
f812a230ac Improve generateSchemaSql.php/generateSchemaChangeSql.php
When --sql is missing, use the folder of the json file as default,
not core's maintenance file (it would generate into core's
tables-generated.sql by default)

The suggested sql file name should end with -generated.sql,
when it starts with tables, this gives tables-generated.sql on default,
but also matches many extensions file names

Change-Id: I9bfa5e16d82da14572e6bbb3da04e06ee80d9128
2022-07-26 21:35:57 +02:00
Umherirrender
68cef1ab99 Various whitespace changes
Change-Id: I31f316c66b3066461b9297c7b6f9845ade99f0df
2022-07-12 20:07:23 +02:00
Tim Starling
a5ce7b6602 Fix generateSchemaSql.php default output path
generateSchemaSql.php with no arguments fails for me because it tries to
read and write $IP/maintenance as if it were a file.

Use the loop body from the "all" case to reduce the amount of
duplicated logic. But it needs a special case so that
--sql=file.sql --type=sqlite writes to the specified file instead of
adding a subdirectory.

Change-Id: Ic88b5ea342d5e48e5465f1b0cbeff36b669a05a3
2022-02-28 14:28:41 +11:00
mainframe98
de0c4819d1 Add validation for abstract schema
This adds an option to the schema generating maintenance scripts to
validate abstract schemas and schema changes and a structure test to
validate exisiting schemas and schema changes. Schemas are also
validated when generating.

The validation for the schema doesn't impose limits on table, index or
column names as I couldn't find any reliable conventions for them.

The structure tests only cover MediaWiki itself as there is no
convention on where extensions store their abstract schema.
Ideally, auto detection would be possible for sql/, but for now
extensions have to define their own (thankfully trivial) tests.

A couple of invalid definitions were fixed thanks to these tests.

I aimed to be thorough, but not all parts of the abstract schema
are completely clear, and Doctrine's documentation is not complete.
As a result, not everything has a description field.

Bug: T298320
Change-Id: I681d265317d4d1584869142ebb23d4098c06885f
2022-02-22 17:41:08 +00:00
mainframe98
a3c6ebba98 Generate abstract schemas with one script call
This rewrites both generateSchemaChangeSql.php and generateSchemaSql.php
to deduplicate logic and adds the 'all' option to --type to generate
schemas for each supported DBMS platform.

Specifying a path with --sql will have the script insert a directory
named after the platform, but only when --type=all is provided.
Only if a directory named mysql/ exists will sql files for mysql be
placed there, to allow using a setup similar to MediaWiki, where only
non-mysql types have their sql files placed in dedicated directories.

This also adds preparations for T298320, so that the abstract schema
can be validated and any errors can be handled before generating a
schema.

Bug: T268587
Change-Id: Ief8282017c8d38659b79262afb8fc691b5bda256
2022-02-11 18:50:25 +01:00