Skip to content

Commit

Permalink
Fix matomo-org#11596: Compatibility of Piwik with MySQL Group Replica…
Browse files Browse the repository at this point in the history
…tion and MySQL InnoDB Cluster (matomo-org#11885)

* Columns added to support mysql group replication (every table must have a primary key)

* changed integer to bigint as "there are issues at other places where INTEGER is simply too small."

* Update script created for 3.1.0 to Fix matomo-org#11596

* corrected php syntax and made the columns primary keys on add

* updated the db upgrade to reflect the inclusion in version 3.2 instead of 3.1

* changed tabs to spaces

* replaced tabs with spaces

* Use consistent column names

* Use consistent column names

* Will be in 3.2.1

* Change Update version + bump version.

* Version bump fail.
  • Loading branch information
Aardvark8 authored and InfinityVoid committed Oct 11, 2018
1 parent 9ae202d commit 6cc320a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 11 deletions.
26 changes: 16 additions & 10 deletions core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,25 @@ public function getTablesCreateSql()
",

'plugin_setting' => "CREATE TABLE {$prefixTables}plugin_setting (
`plugin_name` VARCHAR(60) NOT NULL,
`setting_name` VARCHAR(255) NOT NULL,
`setting_value` LONGTEXT NOT NULL,
`json_encoded` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`user_login` VARCHAR(100) NOT NULL DEFAULT '',
`plugin_name` VARCHAR(60) NOT NULL,
`setting_name` VARCHAR(255) NOT NULL,
`setting_value` LONGTEXT NOT NULL,
`json_encoded` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`user_login` VARCHAR(100) NOT NULL DEFAULT '',
`idplugin_setting` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (idplugin_setting),
INDEX(plugin_name, user_login)
) ENGINE=$engine DEFAULT CHARSET=utf8
",

'site_setting' => "CREATE TABLE {$prefixTables}site_setting (
idsite INTEGER(10) UNSIGNED NOT NULL,
`plugin_name` VARCHAR(60) NOT NULL,
`setting_name` VARCHAR(255) NOT NULL,
`setting_value` LONGTEXT NOT NULL,
`json_encoded` TINYINT UNSIGNED NOT NULL DEFAULT 0,
idsite INTEGER(10) UNSIGNED NOT NULL,
`plugin_name` VARCHAR(60) NOT NULL,
`setting_name` VARCHAR(255) NOT NULL,
`setting_value` LONGTEXT NOT NULL,
`json_encoded` TINYINT UNSIGNED NOT NULL DEFAULT 0,
`idsite_setting` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (idsite_setting),
INDEX(idsite, plugin_name)
) ENGINE=$engine DEFAULT CHARSET=utf8
",
Expand Down Expand Up @@ -210,6 +214,8 @@ public function getTablesCreateSql()
query TEXT NOT NULL,
count INTEGER UNSIGNED NULL,
sum_time_ms FLOAT NULL,
idprofiling BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (idprofiling),
UNIQUE KEY query(query(100))
) ENGINE=$engine DEFAULT CHARSET=utf8
",
Expand Down
90 changes: 90 additions & 0 deletions core/Updates/3.6.0-b1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Updates;

use Piwik\Common;
use Piwik\Db;
use Piwik\Updater;
use Piwik\Updater\Migration;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates;

/**
* Update for version 3.6.0-b1.
*/
class Updates_3_6_0_b1 extends Updates
{
/**
* @var MigrationFactory
*/
private $migration;

private $pluginSettingsTable = 'plugin_setting';
private $siteSettingsTable = 'site_setting';
private $logProfilingTable = 'log_profiling';

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

/**
* Here you can define one or multiple SQL statements that should be executed during the update.
* @param Updater $updater
* @return Migration[]
*/
public function getMigrations(Updater $updater)
{
$migrations = [];
$migrations = $this->getPluginSettingsMigrations($migrations);
$migrations = $this->getSiteSettingsMigrations($migrations);
$migrations = $this->getLogProfilingMigrations($migrations);

return $migrations;
}

public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
}

/**
* @param Migration[] $queries
* @return Migration[]
*/
private function getPluginSettingsMigrations($queries)
{
$queries[] = $this->migration->db->addColumn($this->pluginSettingsTable, 'idplugin_setting', 'BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT');

return $queries;
}

/**
* @param Migration[] $queries
* @return Migration[]
*/
private function getSiteSettingsMigrations($queries)
{
$queries[] = $this->migration->db->addColumn($this->siteSettingsTable, 'idsite_setting', 'BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT');

return $queries;
}

/**
* @param Migration[] $queries
* @return Migration[]
*/
private function getLogProfilingMigrations($queries)
{
$queries[] = $this->migration->db->addColumn($this->logProfilingTable, 'idprofiling', 'BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT');

return $queries;
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Version
* The current Matomo version.
* @var string
*/
const VERSION = '3.5.1';
const VERSION = '3.6.0-b1';

public function isStableVersion($version)
{
Expand Down

0 comments on commit 6cc320a

Please sign in to comment.