Skip to content

Commit

Permalink
Correct schema drift between abstract and old non-abstract
Browse files Browse the repository at this point in the history
The logging feature is broken with the provided schema:
Out of range value for column 'wll_receiver_registration' at row 1

Bug: T299800
Follow-Up: I9daf09b54c262f8ee366cf197f42ab8b6233310a
Change-Id: I5347bb400fe6148beee802c4e87092156454c25f
  • Loading branch information
umherirrender committed Feb 1, 2022
1 parent 859faec commit 90a1d25
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 28 deletions.
22 changes: 19 additions & 3 deletions includes/Hooks.php
Expand Up @@ -28,17 +28,33 @@ class Hooks {
*/
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
$dbType = $updater->getDB()->getType();
$path = dirname( __DIR__ ) . '/patches';
if ( $dbType === 'mysql' ) {
$updater->addExtensionTable( 'wikilove_log',
dirname( __DIR__ ) . '/patches/tables-generated.sql'
$path . '/tables-generated.sql'
);
$updater->modifyExtensionField(
'wikilove_log',
'wll_timestamp',
$path . '/patch-wikilove_log-cleanup.sql'
);
} elseif ( $dbType === 'sqlite' ) {
$updater->addExtensionTable( 'wikilove_log',
dirname( __DIR__ ) . '/patches/sqlite/tables-generated.sql'
$path . '/sqlite/tables-generated.sql'
);
$updater->modifyExtensionField(
'wikilove_log',
'wll_timestamp',
$path . '/sqlite/patch-wikilove_log-cleanup.sql'
);
} elseif ( $dbType === 'postgres' ) {
$updater->addExtensionTable( 'wikilove_log',
dirname( __DIR__ ) . '/patches/postgres/tables-generated.sql'
$path . '/postgres/tables-generated.sql'
);
$updater->modifyExtensionField(
'wikilove_log',
'wll_timestamp',
$path . '/postgrespatch-wikilove_log-cleanup.sql'
);
}
}
Expand Down
206 changes: 206 additions & 0 deletions patches/abstractSchemaChanges/patch-wikilove_log-cleanup.json
@@ -0,0 +1,206 @@
{
"comment": "Correct field type of timestamp columns after abstract schema migration - T299800",
"before": {
"name": "wikilove_log",
"comment": "WikiLove logging schema. Logs all actions of giving WikiLove.",
"columns": [
{
"name": "wll_id",
"comment": "unique id",
"type": "integer",
"options": { "notnull": true, "autoincrement": true }
},
{
"name": "wll_timestamp",
"comment": "timestamp",
"type": "binary",
"options": { "notnull": true, "length": 14 }
},
{
"name": "wll_sender",
"comment": "user id of the sender",
"type": "integer",
"options": { "notnull": true, "unsigned": true }
},
{
"name": "wll_sender_registration",
"comment": "registration date of the sender",
"type": "binary",
"options": { "notnull": false, "length": 14, "default": null }
},
{
"name": "wll_sender_editcount",
"comment": "wll_sender_editcount",
"type": "integer",
"options": { "notnull": false }
},
{
"name": "wll_receiver",
"comment": "user id of reciever",
"type": "integer",
"options": { "notnull": true, "unsigned": true }
},
{
"name": "wll_receiver_registration",
"comment": "registration date of the receiver",
"type": "integer",
"options": { "notnull": false, "default": null }
},
{
"name": "wll_receiver_editcount",
"comment": "total number of edits for the receiver",
"type": "integer",
"options": { "notnull": true }
},
{
"name": "wll_type",
"comment": "type (and subtype) of message",
"type": "string",
"options": { "notnull": true, "length": 64 }
},
{
"name": "wll_subject",
"comment": "subject line",
"type": "string",
"options": { "notnull": true, "length": 255 }
},
{
"name": "wll_message",
"comment": "actual message",
"type": "blob",
"options": { "notnull": true, "length": 65530 }
},
{
"name": "wll_email",
"comment": "whether or not a notification mail has been sent",
"type": "integer",
"options": { "notnull": true, "default": 0 }
}
],
"indexes": [
{
"name": "wll_timestamp",
"columns": [ "wll_timestamp" ],
"unique": false
},
{
"name": "wll_type_time",
"columns": [ "wll_type", "wll_timestamp" ],
"unique": false
},
{
"name": "wll_sender_time",
"columns": [ "wll_sender", "wll_timestamp" ],
"unique": false
},
{
"name": "wll_receiver_time",
"columns": [ "wll_receiver", "wll_timestamp" ],
"unique": false
}
],
"pk": [ "wll_id" ]
},
"after": {
"name": "wikilove_log",
"comment": "WikiLove logging schema. Logs all actions of giving WikiLove.",
"columns": [
{
"name": "wll_id",
"comment": "unique id",
"type": "integer",
"options": { "notnull": true, "autoincrement": true }
},
{
"name": "wll_timestamp",
"comment": "timestamp",
"type": "mwtimestamp",
"options": { "notnull": true }
},
{
"name": "wll_sender",
"comment": "user id of the sender",
"type": "integer",
"options": { "notnull": true, "unsigned": true }
},
{
"name": "wll_sender_registration",
"comment": "registration date of the sender",
"type": "mwtimestamp",
"options": { "notnull": false }
},
{
"name": "wll_sender_editcount",
"comment": "wll_sender_editcount",
"type": "integer",
"options": { "notnull": false }
},
{
"name": "wll_receiver",
"comment": "user id of reciever",
"type": "integer",
"options": { "notnull": true, "unsigned": true }
},
{
"name": "wll_receiver_registration",
"comment": "registration date of the receiver",
"type": "mwtimestamp",
"options": { "notnull": false }
},
{
"name": "wll_receiver_editcount",
"comment": "total number of edits for the receiver",
"type": "integer",
"options": { "notnull": false }
},
{
"name": "wll_type",
"comment": "type (and subtype) of message",
"type": "string",
"options": { "notnull": true, "length": 64 }
},
{
"name": "wll_subject",
"comment": "subject line",
"type": "string",
"options": { "notnull": true, "length": 255 }
},
{
"name": "wll_message",
"comment": "actual message",
"type": "blob",
"options": { "notnull": true, "length": 65530 }
},
{
"name": "wll_email",
"comment": "whether or not a notification mail has been sent",
"type": "mwtinyint",
"options": { "notnull": true, "length": 1, "default": 0 }
}
],
"indexes": [
{
"name": "wll_timestamp",
"columns": [ "wll_timestamp" ],
"unique": false
},
{
"name": "wll_type_time",
"comment": "ASSUMPTION: once narrowed down to a single user (sender/receiver), we can afford a filesort as a single users will have only limited WikiLove messages from or to him/her. It's not worth the memory of extra indexes to cover all the combinations (sender/receiver/type => 8 indexes)",
"columns": [ "wll_type", "wll_timestamp" ],
"unique": false
},
{
"name": "wll_sender_time",
"columns": [ "wll_sender", "wll_timestamp" ],
"unique": false
},
{
"name": "wll_receiver_time",
"columns": [ "wll_receiver", "wll_timestamp" ],
"unique": false
}
],
"pk": [ "wll_id" ]
}
}
10 changes: 10 additions & 0 deletions patches/patch-wikilove_log-cleanup.sql
@@ -0,0 +1,10 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: patches/abstractSchemaChanges/patch-wikilove_log-cleanup.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
ALTER TABLE /*_*/wikilove_log
CHANGE wll_timestamp wll_timestamp BINARY(14) NOT NULL,
CHANGE wll_sender_registration wll_sender_registration BINARY(14) DEFAULT NULL,
CHANGE wll_receiver_registration wll_receiver_registration BINARY(14) DEFAULT NULL,
CHANGE wll_receiver_editcount wll_receiver_editcount INT DEFAULT NULL,
CHANGE wll_email wll_email TINYINT(1) DEFAULT 0 NOT NULL;
20 changes: 20 additions & 0 deletions patches/postgres/patch-wikilove_log-cleanup.sql
@@ -0,0 +1,20 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: patches/abstractSchemaChanges/patch-wikilove_log-cleanup.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
ALTER TABLE wikilove_log ALTER wll_timestamp TYPE TIMESTAMPTZ;
ALTER TABLE wikilove_log ALTER wll_timestamp
DROP DEFAULT;
ALTER TABLE wikilove_log ALTER wll_timestamp TYPE TIMESTAMPTZ;
ALTER TABLE wikilove_log ALTER wll_sender_registration TYPE TIMESTAMPTZ;
ALTER TABLE wikilove_log ALTER wll_sender_registration
DROP DEFAULT;
ALTER TABLE wikilove_log ALTER wll_sender_registration TYPE TIMESTAMPTZ;
ALTER TABLE wikilove_log ALTER wll_receiver_registration TYPE TIMESTAMPTZ;
ALTER TABLE wikilove_log ALTER wll_receiver_registration
DROP DEFAULT;
ALTER TABLE wikilove_log ALTER wll_receiver_editcount
DROP NOT NULL;
ALTER TABLE wikilove_log ALTER wll_email TYPE SMALLINT;
ALTER TABLE wikilove_log ALTER wll_email
SET DEFAULT 0;
12 changes: 6 additions & 6 deletions patches/postgres/tables-generated.sql
@@ -1,20 +1,20 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: ./tables.json
-- Source: patches/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE wikilove_log (
wll_id SERIAL NOT NULL,
wll_timestamp TEXT NOT NULL,
wll_timestamp TIMESTAMPTZ NOT NULL,
wll_sender INT NOT NULL,
wll_sender_registration TEXT DEFAULT NULL,
wll_sender_registration TIMESTAMPTZ DEFAULT NULL,
wll_sender_editcount INT DEFAULT NULL,
wll_receiver INT NOT NULL,
wll_receiver_registration INT DEFAULT NULL,
wll_receiver_editcount INT NOT NULL,
wll_receiver_registration TIMESTAMPTZ DEFAULT NULL,
wll_receiver_editcount INT DEFAULT NULL,
wll_type VARCHAR(64) NOT NULL,
wll_subject VARCHAR(255) NOT NULL,
wll_message TEXT NOT NULL,
wll_email INT DEFAULT 0 NOT NULL,
wll_email SMALLINT DEFAULT 0 NOT NULL,
PRIMARY KEY(wll_id)
);

Expand Down
21 changes: 21 additions & 0 deletions patches/sqlite/patch-wikilove_log-cleanup.sql
@@ -0,0 +1,21 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: patches/abstractSchemaChanges/patch-wikilove_log-cleanup.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
DROP INDEX wll_timestamp;
DROP INDEX wll_type_time;
DROP INDEX wll_sender_time;
DROP INDEX wll_receiver_time;
CREATE TEMPORARY TABLE /*_*/__temp__wikilove_log AS
SELECT wll_id, wll_timestamp, wll_sender, wll_sender_registration, wll_sender_editcount, wll_receiver, wll_receiver_registration, wll_receiver_editcount, wll_type, wll_subject, wll_message, wll_email
FROM /*_*/wikilove_log;
DROP TABLE /*_*/wikilove_log;
CREATE TABLE /*_*/wikilove_log ( wll_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, wll_timestamp BLOB NOT NULL, wll_sender INTEGER UNSIGNED NOT NULL, wll_sender_registration BLOB DEFAULT NULL, wll_sender_editcount INTEGER DEFAULT NULL, wll_receiver INTEGER UNSIGNED NOT NULL, wll_receiver_registration BLOB DEFAULT NULL, wll_receiver_editcount INTEGER DEFAULT NULL, wll_type VARCHAR(64) NOT NULL, wll_subject VARCHAR(255) NOT NULL, wll_message BLOB NOT NULL, wll_email SMALLINT DEFAULT 0 NOT NULL );
INSERT INTO /*_*/wikilove_log ( wll_id, wll_timestamp, wll_sender, wll_sender_registration, wll_sender_editcount, wll_receiver, wll_receiver_registration, wll_receiver_editcount, wll_type, wll_subject, wll_message, wll_email )
SELECT wll_id, wll_timestamp, wll_sender, wll_sender_registration, wll_sender_editcount, wll_receiver, wll_receiver_registration, wll_receiver_editcount, wll_type, wll_subject, wll_message, wll_email
FROM /*_*/__temp__wikilove_log;
DROP TABLE /*_*/__temp__wikilove_log;
CREATE INDEX wll_timestamp ON /*_*/wikilove_log (wll_timestamp);
CREATE INDEX wll_type_time ON /*_*/wikilove_log (wll_type, wll_timestamp);
CREATE INDEX wll_sender_time ON /*_*/wikilove_log (wll_sender, wll_timestamp);
CREATE INDEX wll_receiver_time ON /*_*/wikilove_log (wll_receiver, wll_timestamp);
8 changes: 4 additions & 4 deletions patches/sqlite/tables-generated.sql
@@ -1,5 +1,5 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: ./tables.json
-- Source: patches/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/wikilove_log (
Expand All @@ -9,12 +9,12 @@ CREATE TABLE /*_*/wikilove_log (
wll_sender_registration BLOB DEFAULT NULL,
wll_sender_editcount INTEGER DEFAULT NULL,
wll_receiver INTEGER UNSIGNED NOT NULL,
wll_receiver_registration INTEGER DEFAULT NULL,
wll_receiver_editcount INTEGER NOT NULL,
wll_receiver_registration BLOB DEFAULT NULL,
wll_receiver_editcount INTEGER DEFAULT NULL,
wll_type VARCHAR(64) NOT NULL,
wll_subject VARCHAR(255) NOT NULL,
wll_message BLOB NOT NULL,
wll_email INTEGER DEFAULT 0 NOT NULL
wll_email SMALLINT DEFAULT 0 NOT NULL
);

CREATE INDEX wll_timestamp ON /*_*/wikilove_log (wll_timestamp);
Expand Down
12 changes: 6 additions & 6 deletions patches/tables-generated.sql
@@ -1,20 +1,20 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: ./tables.json
-- Source: patches/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/wikilove_log (
wll_id INT AUTO_INCREMENT NOT NULL,
wll_timestamp VARBINARY(14) NOT NULL,
wll_timestamp BINARY(14) NOT NULL,
wll_sender INT UNSIGNED NOT NULL,
wll_sender_registration VARBINARY(14) DEFAULT NULL,
wll_sender_registration BINARY(14) DEFAULT NULL,
wll_sender_editcount INT DEFAULT NULL,
wll_receiver INT UNSIGNED NOT NULL,
wll_receiver_registration INT DEFAULT NULL,
wll_receiver_editcount INT NOT NULL,
wll_receiver_registration BINARY(14) DEFAULT NULL,
wll_receiver_editcount INT DEFAULT NULL,
wll_type VARCHAR(64) NOT NULL,
wll_subject VARCHAR(255) NOT NULL,
wll_message BLOB NOT NULL,
wll_email INT DEFAULT 0 NOT NULL,
wll_email TINYINT(1) DEFAULT 0 NOT NULL,
INDEX wll_timestamp (wll_timestamp),
INDEX wll_type_time (wll_type, wll_timestamp),
INDEX wll_sender_time (wll_sender, wll_timestamp),
Expand Down

0 comments on commit 90a1d25

Please sign in to comment.