Make newlines in generated schemas more consistent

Previously, a first str_replace() would add a single newline before any
CREATE (TABLE or INDEX), and then a second one would add another newline
after the $wgDBTableOptions, resulting in a blank line between any two
CREATEs and also a newline at the end of the file – at least for MySQL
schemas. But PostgreSQL and SQLite schemas don’t use $wgDBTableOptions,
so the second str_replace() was a no-op for them, and they got no blank
line between CREATEs nor a newline at the end of the file. Fix this by
making the first str_replace() insert two newlines and appending a final
newline all the time.

Bug: T260779
Change-Id: Idcc4fae76d382b559f21234f8a6f49e537a60f11
This commit is contained in:
Lucas Werkmeister 2020-08-19 12:03:24 +02:00
parent d39861bdc3
commit 639bd2178e
3 changed files with 66 additions and 5 deletions

View file

@ -96,17 +96,18 @@ class GenerateSchemaSql extends Maintenance {
// Until the linting issue is resolved
// https://github.com/doctrine/sql-formatter/issues/53
$sql = str_replace( "\n/*_*/\n", " /*_*/", $sql );
$sql = str_replace( "; CREATE ", ";\nCREATE ", $sql );
$sql = str_replace( "; CREATE ", ";\n\nCREATE ", $sql );
$sql = str_replace(
"\n" . '/*$wgDBTableOptions*/' . ";",
' /*$wgDBTableOptions*/;' . "\n",
' /*$wgDBTableOptions*/;',
$sql
);
$sql = str_replace(
"\n" . '/*$wgDBTableOptions*/' . "\n;",
' /*$wgDBTableOptions*/;' . "\n",
' /*$wgDBTableOptions*/;',
$sql
);
$sql .= "\n";
file_put_contents( $sqlPath, $sql );
}

View file

@ -8,26 +8,34 @@ CREATE TABLE site_identifiers (
si_site INT NOT NULL,
PRIMARY KEY(si_type, si_key)
);
CREATE INDEX site_ids_site ON site_identifiers (si_site);
CREATE INDEX site_ids_key ON site_identifiers (si_key);
CREATE TABLE updatelog (
ul_key VARCHAR(255) NOT NULL,
ul_value TEXT DEFAULT NULL,
PRIMARY KEY(ul_key)
);
CREATE TABLE actor (
actor_id BIGSERIAL NOT NULL,
actor_user INT DEFAULT NULL,
actor_name TEXT NOT NULL,
PRIMARY KEY(actor_id)
);
CREATE UNIQUE INDEX actor_user ON actor (actor_user);
CREATE UNIQUE INDEX actor_name ON actor (actor_name);
CREATE TABLE user_former_groups (
ufg_user INT DEFAULT 0 NOT NULL,
ufg_group TEXT DEFAULT '' NOT NULL,
PRIMARY KEY(ufg_user, ufg_group)
);
CREATE TABLE bot_passwords (
bp_user INT NOT NULL,
bp_app_id TEXT NOT NULL,
@ -37,6 +45,7 @@ CREATE TABLE bot_passwords (
bp_grants TEXT NOT NULL,
PRIMARY KEY(bp_user, bp_app_id)
);
CREATE TABLE comment (
comment_id BIGSERIAL NOT NULL,
comment_hash INT NOT NULL,
@ -44,7 +53,9 @@ CREATE TABLE comment (
comment_data TEXT DEFAULT NULL,
PRIMARY KEY(comment_id)
);
CREATE INDEX comment_hash ON comment (comment_hash);
CREATE TABLE slots (
slot_revision_id BIGINT NOT NULL,
slot_role_id SMALLINT NOT NULL,
@ -52,9 +63,11 @@ CREATE TABLE slots (
slot_origin BIGINT NOT NULL,
PRIMARY KEY(slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON slots (
slot_revision_id, slot_origin, slot_role_id
);
CREATE TABLE site_stats (
ss_row_id INT NOT NULL,
ss_total_edits BIGINT DEFAULT NULL,
@ -65,20 +78,25 @@ CREATE TABLE site_stats (
ss_images BIGINT DEFAULT NULL,
PRIMARY KEY(ss_row_id)
);
CREATE TABLE user_properties (
up_user INT NOT NULL,
up_property TEXT NOT NULL,
up_value TEXT DEFAULT NULL,
PRIMARY KEY(up_user, up_property)
);
CREATE INDEX user_properties_property ON user_properties (up_property);
CREATE TABLE log_search (
ls_field TEXT NOT NULL,
ls_value VARCHAR(255) NOT NULL,
ls_log_id INT DEFAULT 0 NOT NULL,
PRIMARY KEY(ls_field, ls_value, ls_log_id)
);
CREATE INDEX ls_log_id ON log_search (ls_log_id);
CREATE TABLE change_tag (
ct_id SERIAL NOT NULL,
ct_rc_id INT DEFAULT NULL,
@ -88,12 +106,17 @@ CREATE TABLE change_tag (
ct_tag_id INT NOT NULL,
PRIMARY KEY(ct_id)
);
CREATE UNIQUE INDEX change_tag_rc_tag_id ON change_tag (ct_rc_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_log_tag_id ON change_tag (ct_log_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_rev_tag_id ON change_tag (ct_rev_id, ct_tag_id);
CREATE INDEX change_tag_tag_id_id ON change_tag (
ct_tag_id, ct_rc_id, ct_rev_id, ct_log_id
);
CREATE TABLE content (
content_id BIGSERIAL NOT NULL,
content_size INT NOT NULL,
@ -102,18 +125,21 @@ CREATE TABLE content (
content_address TEXT NOT NULL,
PRIMARY KEY(content_id)
);
CREATE TABLE l10n_cache (
lc_lang TEXT NOT NULL,
lc_key VARCHAR(255) NOT NULL,
lc_value TEXT NOT NULL,
PRIMARY KEY(lc_lang, lc_key)
);
CREATE TABLE module_deps (
md_module TEXT NOT NULL,
md_skin TEXT NOT NULL,
md_deps TEXT NOT NULL,
PRIMARY KEY(md_module, md_skin)
);
CREATE TABLE redirect (
rd_from INT DEFAULT 0 NOT NULL,
rd_namespace INT DEFAULT 0 NOT NULL,
@ -122,7 +148,9 @@ CREATE TABLE redirect (
rd_fragment TEXT DEFAULT NULL,
PRIMARY KEY(rd_from)
);
CREATE INDEX rd_ns_title ON redirect (rd_namespace, rd_title, rd_from);
CREATE TABLE pagelinks (
pl_from INT DEFAULT 0 NOT NULL,
pl_namespace INT DEFAULT 0 NOT NULL,
@ -130,8 +158,10 @@ CREATE TABLE pagelinks (
pl_from_namespace INT DEFAULT 0 NOT NULL,
PRIMARY KEY(pl_from, pl_namespace, pl_title)
);
CREATE INDEX pl_namespace ON pagelinks (pl_namespace, pl_title, pl_from);
CREATE INDEX pl_backlinks_namespace ON pagelinks (
pl_from_namespace, pl_namespace,
pl_title, pl_from
);
);

View file

@ -8,25 +8,33 @@ CREATE TABLE /*_*/site_identifiers (
si_site INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(si_type, si_key)
);
CREATE INDEX site_ids_site ON /*_*/site_identifiers (si_site);
CREATE INDEX site_ids_key ON /*_*/site_identifiers (si_key);
CREATE TABLE /*_*/updatelog (
ul_key VARCHAR(255) NOT NULL,
ul_value BLOB DEFAULT NULL,
PRIMARY KEY(ul_key)
);
CREATE TABLE /*_*/actor (
actor_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
actor_user INTEGER UNSIGNED DEFAULT NULL,
actor_name BLOB NOT NULL
);
CREATE UNIQUE INDEX actor_user ON /*_*/actor (actor_user);
CREATE UNIQUE INDEX actor_name ON /*_*/actor (actor_name);
CREATE TABLE /*_*/user_former_groups (
ufg_user INTEGER UNSIGNED DEFAULT 0 NOT NULL,
ufg_group BLOB DEFAULT '' NOT NULL,
PRIMARY KEY(ufg_user, ufg_group)
);
CREATE TABLE /*_*/bot_passwords (
bp_user INTEGER UNSIGNED NOT NULL,
bp_app_id BLOB NOT NULL,
@ -36,12 +44,15 @@ CREATE TABLE /*_*/bot_passwords (
bp_grants BLOB NOT NULL,
PRIMARY KEY(bp_user, bp_app_id)
);
CREATE TABLE /*_*/comment (
comment_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
comment_hash INTEGER NOT NULL, comment_text BLOB NOT NULL,
comment_data BLOB DEFAULT NULL
);
CREATE INDEX comment_hash ON /*_*/comment (comment_hash);
CREATE TABLE /*_*/slots (
slot_revision_id BIGINT UNSIGNED NOT NULL,
slot_role_id SMALLINT UNSIGNED NOT NULL,
@ -49,9 +60,11 @@ CREATE TABLE /*_*/slots (
slot_origin BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON /*_*/slots (
slot_revision_id, slot_origin, slot_role_id
);
CREATE TABLE /*_*/site_stats (
ss_row_id INTEGER UNSIGNED NOT NULL,
ss_total_edits BIGINT UNSIGNED DEFAULT NULL,
@ -62,20 +75,25 @@ CREATE TABLE /*_*/site_stats (
ss_images BIGINT UNSIGNED DEFAULT NULL,
PRIMARY KEY(ss_row_id)
);
CREATE TABLE /*_*/user_properties (
up_user INTEGER UNSIGNED NOT NULL,
up_property BLOB NOT NULL,
up_value BLOB DEFAULT NULL,
PRIMARY KEY(up_user, up_property)
);
CREATE INDEX user_properties_property ON /*_*/user_properties (up_property);
CREATE TABLE /*_*/log_search (
ls_field BLOB NOT NULL,
ls_value VARCHAR(255) NOT NULL,
ls_log_id INTEGER UNSIGNED DEFAULT 0 NOT NULL,
PRIMARY KEY(ls_field, ls_value, ls_log_id)
);
CREATE INDEX ls_log_id ON /*_*/log_search (ls_log_id);
CREATE TABLE /*_*/change_tag (
ct_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
ct_rc_id INTEGER UNSIGNED DEFAULT NULL,
@ -83,30 +101,38 @@ CREATE TABLE /*_*/change_tag (
ct_rev_id INTEGER UNSIGNED DEFAULT NULL,
ct_params BLOB DEFAULT NULL, ct_tag_id INTEGER UNSIGNED NOT NULL
);
CREATE UNIQUE INDEX change_tag_rc_tag_id ON /*_*/change_tag (ct_rc_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_log_tag_id ON /*_*/change_tag (ct_log_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_rev_tag_id ON /*_*/change_tag (ct_rev_id, ct_tag_id);
CREATE INDEX change_tag_tag_id_id ON /*_*/change_tag (
ct_tag_id, ct_rc_id, ct_rev_id, ct_log_id
);
CREATE TABLE /*_*/content (
content_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
content_size INTEGER UNSIGNED NOT NULL,
content_sha1 BLOB NOT NULL, content_model SMALLINT UNSIGNED NOT NULL,
content_address BLOB NOT NULL
);
CREATE TABLE /*_*/l10n_cache (
lc_lang BLOB NOT NULL,
lc_key VARCHAR(255) NOT NULL,
lc_value BLOB NOT NULL,
PRIMARY KEY(lc_lang, lc_key)
);
CREATE TABLE /*_*/module_deps (
md_module BLOB NOT NULL,
md_skin BLOB NOT NULL,
md_deps BLOB NOT NULL,
PRIMARY KEY(md_module, md_skin)
);
CREATE TABLE /*_*/redirect (
rd_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
rd_namespace INTEGER DEFAULT 0 NOT NULL,
@ -115,7 +141,9 @@ CREATE TABLE /*_*/redirect (
rd_fragment BLOB DEFAULT NULL,
PRIMARY KEY(rd_from)
);
CREATE INDEX rd_ns_title ON /*_*/redirect (rd_namespace, rd_title, rd_from);
CREATE TABLE /*_*/pagelinks (
pl_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
pl_namespace INTEGER DEFAULT 0 NOT NULL,
@ -123,8 +151,10 @@ CREATE TABLE /*_*/pagelinks (
pl_from_namespace INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY(pl_from, pl_namespace, pl_title)
);
CREATE INDEX pl_namespace ON /*_*/pagelinks (pl_namespace, pl_title, pl_from);
CREATE INDEX pl_backlinks_namespace ON /*_*/pagelinks (
pl_from_namespace, pl_namespace,
pl_title, pl_from
);
);