aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2021-08-30 17:30:55 +0200
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2021-09-01 15:12:27 +0200
commiteddc17064d610dbcf372739dd5c5fd2caa788048 (patch)
tree59aa5edab77d02d093d6d6eaa983dccc24cae3a9 /lib
parent98be3c32ea9dd9fdce4616c9b1d425c8cb979309 (diff)
rename all migrations to 1.x
Diffstat (limited to 'lib')
-rw-r--r--lib/classes/StudipCacheFactory.class.php2
-rw-r--r--lib/migrations/DBSchemaVersion.php37
-rw-r--r--lib/migrations/Migrator.php5
3 files changed, 33 insertions, 11 deletions
diff --git a/lib/classes/StudipCacheFactory.class.php b/lib/classes/StudipCacheFactory.class.php
index cc7be15..5ce2985 100644
--- a/lib/classes/StudipCacheFactory.class.php
+++ b/lib/classes/StudipCacheFactory.class.php
@@ -189,7 +189,7 @@ class StudipCacheFactory
# default class
if (is_null($cache_class)) {
$version = new DBSchemaVersion();
- if ($version->get() < 224) {
+ if ($version->get(1) < 224) {
// db cache is not yet available, use StudipMemoryCache
return 'StudipMemoryCache';
}
diff --git a/lib/migrations/DBSchemaVersion.php b/lib/migrations/DBSchemaVersion.php
index 207a804..8217ec0 100644
--- a/lib/migrations/DBSchemaVersion.php
+++ b/lib/migrations/DBSchemaVersion.php
@@ -93,7 +93,8 @@ class DBSchemaVersion implements SchemaVersion
private function initSchemaInfo()
{
if (!$this->branchSupported()) {
- $query = "SELECT 0, version FROM schema_version WHERE domain = ?";
+ $branch = $this->domain === 'studip' ? 1 : 0;
+ $query = "SELECT $branch, version FROM schema_version WHERE domain = ?";
} else {
$query = "SELECT branch, version FROM schema_version WHERE domain = ? ORDER BY branch";
}
@@ -101,8 +102,8 @@ class DBSchemaVersion implements SchemaVersion
$statement->execute([$this->domain]);
$versions = $statement->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE);
- if ($versions) {
- $this->versions = array_map('intval', $versions);
+ foreach ($versions as $branch => $version) {
+ $this->versions[$branch] = (int) $version;
}
}
@@ -114,7 +115,7 @@ class DBSchemaVersion implements SchemaVersion
*/
public function get($branch = 0)
{
- return $this->versions[$branch ?: $this->branch];
+ return $this->versions[$branch];
}
/**
@@ -125,7 +126,7 @@ class DBSchemaVersion implements SchemaVersion
*/
public function set($version, $branch = 0)
{
- $this->versions[$branch ?: $this->branch] = (int) $version;
+ $this->versions[$branch] = (int) $version;
if (!$this->branchSupported()) {
$query = "INSERT INTO schema_version (domain, version)
@@ -143,7 +144,7 @@ class DBSchemaVersion implements SchemaVersion
$statement = DBManager::get()->prepare($query);
$statement->execute([
$this->domain,
- $branch ?: $this->branch,
+ $branch,
$version
]);
}
@@ -164,14 +165,18 @@ class DBSchemaVersion implements SchemaVersion
if ($result && $result->rowCount() > 0) {
$backported_migrations = [
- 20200306, 20200306, 20200713, 20200811, 20200909,
- 20200910, 20201002, 20201103, 202011031, 20210317
+ 20200306, 20200713, 20200811, 20200909, 20200910,
+ 20201002, 20201103, 202011031, 20210317
];
$query = "DELETE FROM schema_versions
WHERE domain = 'studip' AND version in (?)";
$db->execute($query, [$backported_migrations]);
+ $query = "DELETE FROM schema_versions
+ WHERE domain = 'studip' AND LENGTH(version) > 8";
+ $db->exec($query);
+
$query = "CREATE TABLE schema_version (
domain VARCHAR(255) COLLATE latin1_bin NOT NULL,
branch VARCHAR(64) COLLATE latin1_bin NOT NULL DEFAULT '0',
@@ -187,6 +192,22 @@ class DBSchemaVersion implements SchemaVersion
$query = "DROP TABLE schema_versions";
$db->exec($query);
+
+ $schema_mapping = [
+ 20190917 => 269,
+ 20200307 => 285,
+ 20200522 => 290,
+ 20210603 => 328
+ ];
+
+ $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]);
+ }
}
}
}
diff --git a/lib/migrations/Migrator.php b/lib/migrations/Migrator.php
index eb0193a..a959317 100644
--- a/lib/migrations/Migrator.php
+++ b/lib/migrations/Migrator.php
@@ -194,16 +194,17 @@ class Migrator
public function migrateTo($target_version)
{
$migrations = $this->relevantMigrations($target_version);
+ $target_branch = $this->schema_version->getBranch();
# you're on the right version
if (empty($migrations)) {
- $this->log('You are already at %d.', $this->schema_version->get());
+ $this->log('You are already at %d.', $this->schema_version->get($target_branch));
return;
}
$this->log(
'Currently at version %d. Now migrating %s to %d.',
- $this->schema_version->get(),
+ $this->schema_version->get($target_branch),
$this->direction,
max($this->target_versions)
);