Skip to content
Snippets Groups Projects
Unverified Commit 9b12bd30 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Fix column and index-size for MySQL only (#1185)

* Fix column and index-size for MySQL only
parent 759b2c9e
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,6 @@ class LogoutStore ...@@ -41,7 +41,6 @@ class LogoutStore
break; break;
case 'sqlite': case 'sqlite':
/** /**
* TableVersion 2 increased the column size to 255 which is the maximum length of a FQDN
* Because SQLite does not support field alterations, the approach is to: * Because SQLite does not support field alterations, the approach is to:
* Create a new table without the proper column size * Create a new table without the proper column size
* Copy the current data to the new table * Copy the current data to the new table
...@@ -78,25 +77,28 @@ class LogoutStore ...@@ -78,25 +77,28 @@ class LogoutStore
return; return;
} elseif ($tableVer === 2) { } elseif ($tableVer === 2) {
// TableVersion 3 fixes the indexes that were set to 255 in version 2; they cannot be larger than 191 // TableVersion 3 fixes the indexes that were set to 255 in version 2; they cannot be larger than 191 on MySQL
// Drop old indexes
$query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX '.$store->prefix.'_saml_LogoutStore_nameId'; if ($store->driver === 'mysql') {
$store->pdo->exec($query); // Drop old indexes
$query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX _authSource'; $query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX '.$store->prefix.'_saml_LogoutStore_nameId';
$store->pdo->exec($query); $store->pdo->exec($query);
$query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX _authSource';
// Create new indexes $store->pdo->exec($query);
$query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON ';
$query .= $store->prefix.'_saml_LogoutStore (_authSource(191), _nameId)'; // Create new indexes
$store->pdo->exec($query); $query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON ';
$query .= $store->prefix.'_saml_LogoutStore (_authSource(191), _nameId)';
$query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore ADD UNIQUE KEY (_authSource(191), _nameID, _sessionIndex)'; $store->pdo->exec($query);
$store->pdo->exec($query);
$query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore ADD UNIQUE KEY (_authSource(191), _nameID, _sessionIndex)';
$store->pdo->exec($query);
}
$store->setTableVersion('saml_LogoutStore', 3); $store->setTableVersion('saml_LogoutStore', 3);
return; return;
} elseif ($tableVer === 1) { } elseif ($tableVer === 1) {
// TableVersion 2 increased the column size to 255 which is the maximum length of a FQDN // TableVersion 2 increased the column size to 255 (191 for mysql) which is the maximum length of a FQDN
switch ($store->driver) { switch ($store->driver) {
case 'pgsql': case 'pgsql':
// This does not affect the NOT NULL constraint // This does not affect the NOT NULL constraint
...@@ -105,7 +107,6 @@ class LogoutStore ...@@ -105,7 +107,6 @@ class LogoutStore
break; break;
case 'sqlite': case 'sqlite':
/** /**
* TableVersion 2 increased the column size to 255 which is the maximum length of a FQDN
* Because SQLite does not support field alterations, the approach is to: * Because SQLite does not support field alterations, the approach is to:
* Create a new table without the proper column size * Create a new table without the proper column size
* Copy the current data to the new table * Copy the current data to the new table
...@@ -124,6 +125,10 @@ class LogoutStore ...@@ -124,6 +125,10 @@ class LogoutStore
'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON '.$store->prefix.'_saml_LogoutStore (_authSource, _nameId)' 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON '.$store->prefix.'_saml_LogoutStore (_authSource, _nameId)'
]; ];
break; break;
case 'mysql':
$update = ['ALTER TABLE '.$store->prefix.
'_saml_LogoutStore MODIFY _authSource VARCHAR(191) NOT NULL'];
break;
default: default:
$update = ['ALTER TABLE '.$store->prefix. $update = ['ALTER TABLE '.$store->prefix.
'_saml_LogoutStore MODIFY _authSource VARCHAR(255) NOT NULL']; '_saml_LogoutStore MODIFY _authSource VARCHAR(255) NOT NULL'];
...@@ -143,12 +148,12 @@ class LogoutStore ...@@ -143,12 +148,12 @@ class LogoutStore
} }
$query = 'CREATE TABLE '.$store->prefix.'_saml_LogoutStore ( $query = 'CREATE TABLE '.$store->prefix.'_saml_LogoutStore (
_authSource VARCHAR(255) NOT NULL, _authSource VARCHAR('.($store->driver === 'mysql' ? '191' : '255').') NOT NULL,
_nameId VARCHAR(40) NOT NULL, _nameId VARCHAR(40) NOT NULL,
_sessionIndex VARCHAR(50) NOT NULL, _sessionIndex VARCHAR(50) NOT NULL,
_expire DATETIME NOT NULL, _expire DATETIME NOT NULL,
_sessionId VARCHAR(50) NOT NULL, _sessionId VARCHAR(50) NOT NULL,
UNIQUE (_authSource(191), _nameID, _sessionIndex) UNIQUE (_authSource'.($store->driver === 'mysql' ? '(191)' : '').', _nameID, _sessionIndex)
)'; )';
$store->pdo->exec($query); $store->pdo->exec($query);
...@@ -157,7 +162,7 @@ class LogoutStore ...@@ -157,7 +162,7 @@ class LogoutStore
$store->pdo->exec($query); $store->pdo->exec($query);
$query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON '; $query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON ';
$query .= $store->prefix.'_saml_LogoutStore (_authSource(191), _nameId)'; $query .= $store->prefix.'_saml_LogoutStore (_authSource'.($store->driver === 'mysql' ? '(191)' : '').', _nameId)';
$store->pdo->exec($query); $store->pdo->exec($query);
$store->setTableVersion('saml_LogoutStore', 4); $store->setTableVersion('saml_LogoutStore', 4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment