Skip to content
Snippets Groups Projects
Commit f6828d15 authored by Elmar Ludwig's avatar Elmar Ludwig Committed by Jan-Hendrik Willms
Browse files

make schema version mapping more robust, fixes #331 and #337

parent e6a11cb9
No related branches found
No related tags found
No related merge requests found
...@@ -166,21 +166,22 @@ class DBSchemaVersion implements SchemaVersion ...@@ -166,21 +166,22 @@ class DBSchemaVersion implements SchemaVersion
$result = $db->query("SHOW TABLES LIKE 'schema_versions'"); $result = $db->query("SHOW TABLES LIKE 'schema_versions'");
if ($result && $result->rowCount() > 0) { if ($result && $result->rowCount() > 0) {
$backported_migrations = [ $base_version = 269; // 4.4
20200306, 20200713, 20200811, 20200909, 20200910, $schema_mapping = [
20201002, 20201103, 202011031, 20210317, 20210422, 20200307 => 285, // 4.5
20210425, 20210503, 20211015, 20211108, 20200522 => 290, // 4.6
20210511 => 327 // 5.0
]; ];
// drop backported migrations foreach ($schema_mapping as $old_version => $new_version) {
$query = "DELETE FROM schema_versions $query = "SELECT 1 FROM schema_versions
WHERE domain = 'studip' AND version in (?)"; WHERE domain = 'studip' AND version = ?";
$db->execute($query, [$backported_migrations]); $result = $db->fetchOne($query, [$old_version]);
// drop migrations with irregular numbers if ($result) {
$query = "DELETE FROM schema_versions $base_version = $new_version;
WHERE domain = 'studip' AND LENGTH(version) > 8"; }
$db->exec($query); }
$query = "CREATE TABLE schema_version ( $query = "CREATE TABLE schema_version (
domain VARCHAR(255) COLLATE latin1_bin NOT NULL, domain VARCHAR(255) COLLATE latin1_bin NOT NULL,
...@@ -198,22 +199,9 @@ class DBSchemaVersion implements SchemaVersion ...@@ -198,22 +199,9 @@ class DBSchemaVersion implements SchemaVersion
$query = "DROP TABLE schema_versions"; $query = "DROP TABLE schema_versions";
$db->exec($query); $db->exec($query);
$schema_mapping = [ $query = "UPDATE schema_version SET branch = ?, version = ?
20190917 => 269, WHERE domain = 'studip'";
20200307 => 285, $db->execute($query, [1, $base_version]);
20200522 => 290,
20210511 => 327,
20210603 => 327
];
$query = "UPDATE schema_version SET branch = '1' WHERE domain = 'studip'";
$db->exec($query);
foreach ($schema_mapping as $old_version => $new_version) {
$query = "UPDATE schema_version SET version = ?
WHERE domain = 'studip' AND version = ?";
$db->execute($query, [$new_version, $old_version]);
}
} }
} }
} }
...@@ -444,7 +444,7 @@ class Migrator ...@@ -444,7 +444,7 @@ class Migrator
public function migrationBranchAndVersion($version) public function migrationBranchAndVersion($version)
{ {
if (preg_match('/^(.*)\.([0-9]+)$/', $version, $matches)) { if (preg_match('/^(.*)\.([0-9]+)$/', $version, $matches)) {
$branch = preg_replace('/\b0+/', '', $matches[1]); $branch = preg_replace('/\b0+\B/', '', $matches[1]);
$version = (int) $matches[2]; $version = (int) $matches[2];
} else { } else {
$branch = '0'; $branch = '0';
......
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