Repairs necessary for echo to support Sqlite

Sqlite's lack of an 'ALTER TABLE CHANGE' statement has prevented echo from
supporting sqlite, and by relation has prevented Echo's unit tests from
running within the foundations jenkins CI environment.  This patch detects
if the database is currently an sqlite database and applies a specially
formulated patch that performs a rename/copy/delete operation to get
the equivilient of an 'ALTER TABLE CHANGE' command. Additionally renames
one index to have a more unique echo-specific name.

Bug: 41987
Change-Id: I9b6468221ba6fe501b15c563f3301694262eec65
This commit is contained in:
Erik Bernhardson 2013-05-20 10:23:51 -07:00
parent e1be0ace4a
commit 68a4587460
5 changed files with 90 additions and 7 deletions

View file

@ -59,19 +59,31 @@ class EchoHooks {
$updater->addExtensionTable( 'echo_event', $baseSQLFile );
$updater->addExtensionTable( 'echo_email_batch', "$dir/db_patches/echo_email_batch.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_agent', "$dir/db_patches/patch-event_agent-split.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_variant', "$dir/db_patches/patch-event_variant_nullability.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_extra', "$dir/db_patches/patch-event_extra-size.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_agent_ip', "$dir/db_patches/patch-event_agent_ip-size.sql" );
if ( $updater->getDB()->getType() === 'sqlite' ) {
$updater->modifyExtensionField( 'echo_event', 'event_agent', "$dir/db_patches/patch-event_agent-split.sqlite.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_variant', "$dir/db_patches/patch-event_variant_nullability.sqlite.sql" );
// There is no need to run the patch-event_extra-size or patch-event_agent_ip-size because
// sqlite ignores numeric arguments in parentheses that follow the type name (ex: VARCHAR(255))
// see http://www.sqlite.org/datatype3.html Section 2.2 for more info
} else {
$updater->modifyExtensionField( 'echo_event', 'event_agent', "$dir/db_patches/patch-event_agent-split.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_variant', "$dir/db_patches/patch-event_variant_nullability.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_extra', "$dir/db_patches/patch-event_extra-size.sql" );
$updater->modifyExtensionField( 'echo_event', 'event_agent_ip', "$dir/db_patches/patch-event_agent_ip-size.sql" );
}
$updater->addExtensionField( 'echo_notification', 'notification_bundle_base',
"$dir/db_patches/patch-notification-bundling-field.sql" );
$updater->addExtensionIndex( 'echo_event', 'event_type', "$dir/db_patches/patch-alter-type_page-index.sql" );
// This index was renamed twice, first from type_page to event_type and later from event_type to echo_event_type
if ( $updater->getDB()->indexExists( 'echo_event', 'type_page', __METHOD__ ) ) {
$updater->addExtensionIndex( 'echo_event', 'event_type', "$dir/db_patches/patch-alter-type_page-index.sql" );
}
$updater->dropTable( 'echo_subscription' );
$updater->dropExtensionField( 'echo_event', 'event_timestamp', "$dir/db_patches/patch-drop-echo_event-event_timestamp.sql" );
$updater->addExtensionField( 'echo_email_batch', 'eeb_event_hash',
"$dir/db_patches/patch-email_batch-new-field.sql" );
$updater->addExtensionField( 'echo_event', 'event_page_id', "$dir/db_patches/patch-add-echo_event-event_page_id.sql" );
$updater->addExtensionIndex( 'echo_event', 'echo_event_type', "$dir/db_patches/patch-alter-event_type-index.sql" );
return true;
}

View file

@ -0,0 +1,3 @@
DROP INDEX /*i*/event_type ON /*_*/echo_event;
CREATE INDEX /*i*/echo_event_type ON /*_*/echo_event (event_type);

View file

@ -0,0 +1,35 @@
-- Split event_agent field to allow anonymous agents
ALTER TABLE echo_event ADD COLUMN event_agent_id int unsigned null;
ALTER TABLE echo_event ADD COLUMN event_agent_ip varchar binary null;
UPDATE echo_event SET event_agent_id = event_agent;
-- Rename current table to temporary name
ALTER TABLE /*_*/echo_event RENAME TO /*_*/temp_echo_event_split_event_agent;
-- Recreate table using the proper nullability constraint for event_variant
CREATE TABLE /*_*/echo_event (
event_id int unsigned not null primary key auto_increment,
event_type varchar(64) binary not null,
event_variant varchar(64) binary null,
event_agent_id int unsigned null, -- The user who triggered it, if any
event_agent_ip varchar(39) binary null, -- IP address who triggered it, if any
event_page_namespace int unsigned null,
event_page_title varchar(255) binary null,
event_extra BLOB NULL
) /*$wgDBTableOptions*/;
-- Copy over all the old data into the new table
INSERT INTO /*_*/echo_event
(event_id, event_type, event_variant, event_agent_id, event_page_namespace, event_page_title, event_extra)
SELECT
event_id, event_type, event_variant, event_agent, event_page_namespace, event_page_title, event_extra
FROM
/*_*/temp_echo_event_split_event_agent;
-- Drop the original table
DROP TABLE /*_*/temp_echo_event_split_event_agent;
-- recreate indexes
CREATE INDEX /*i*/echo_event_type ON /*_*/echo_event (event_type);

View file

@ -0,0 +1,33 @@
-- Sqlites alter table statement can NOT change existing columns. The only
-- option since we need to change the nullability of event_variant is to
-- recreate the table and copy the data over.
-- Rename current table to temporary name
ALTER TABLE /*_*/echo_event RENAME TO /*_*/temp_echo_event_variant_nullability;
-- Recreate table using the proper nullability constraint for event_variant
CREATE TABLE /*_*/echo_event (
event_id int unsigned not null primary key auto_increment,
event_type varchar(64) binary not null,
event_variant varchar(64) binary null,
event_agent_id int unsigned null, -- The user who triggered it, if any
event_agent_ip varchar(39) binary null, -- IP address who triggered it, if any
event_page_namespace int unsigned null,
event_page_title varchar(255) binary null,
event_extra BLOB NULL
) /*$wgDBTableOptions*/;
-- Copy over all the old data into the new table
INSERT INTO /*_*/echo_event
(event_id, event_type, event_variant, event_agent_id, event_agent_ip, event_page_namespace, event_page_title, event_extra)
SELECT
event_id, event_type, event_variant, event_agent_id, event_agent_ip, event_page_namespace, event_page_title, event_extra
FROM
/*_*/temp_echo_event_variant_nullability;
-- Drop the original table
DROP TABLE /*_*/temp_echo_event_variant_nullability;
-- recreate indexes
CREATE INDEX /*i*/echo_event_type ON /*_*/echo_event (event_type);

View file

@ -12,7 +12,7 @@ CREATE TABLE /*_*/echo_event (
event_page_id int unsigned null
) /*$wgDBTableOptions*/;
CREATE INDEX /*i*/event_type ON /*_*/echo_event (event_type);
CREATE INDEX /*i*/echo_event_type ON /*_*/echo_event (event_type);
CREATE TABLE /*_*/echo_notification (
notification_event int unsigned not null,
@ -24,7 +24,7 @@ CREATE TABLE /*_*/echo_notification (
notification_bundle_display_hash varchar(32) binary not null -- The hash for displaying bundle notifications with regard to timestamp, this is is a subset of notification_bundle_hash
) /*$wgDBTableOptions*/;
CREATE INDEX /*i*/user_timestamp ON /*_*/echo_notification (notification_user,notification_timestamp);
CREATE INDEX /*i*/echo_user_timestamp ON /*_*/echo_notification (notification_user,notification_timestamp);
CREATE UNIQUE INDEX /*i*/user_event ON /*_*/echo_notification (notification_user,notification_event);
CREATE INDEX /*i*/echo_notification_user_base_read_timestamp ON /*_*/echo_notification (notification_user, notification_bundle_base, notification_read_timestamp);
CREATE INDEX /*i*/echo_notification_user_base_timestamp ON /*_*/echo_notification (notification_user, notification_bundle_base, notification_timestamp, notification_event);