Skip to content
Snippets Groups Projects
Commit eddc1706 authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

rename all migrations to 1.x

parent 98be3c32
No related branches found
No related tags found
No related merge requests found
...@@ -189,7 +189,7 @@ class StudipCacheFactory ...@@ -189,7 +189,7 @@ class StudipCacheFactory
# default class # default class
if (is_null($cache_class)) { if (is_null($cache_class)) {
$version = new DBSchemaVersion(); $version = new DBSchemaVersion();
if ($version->get() < 224) { if ($version->get(1) < 224) {
// db cache is not yet available, use StudipMemoryCache // db cache is not yet available, use StudipMemoryCache
return 'StudipMemoryCache'; return 'StudipMemoryCache';
} }
......
...@@ -93,7 +93,8 @@ class DBSchemaVersion implements SchemaVersion ...@@ -93,7 +93,8 @@ class DBSchemaVersion implements SchemaVersion
private function initSchemaInfo() private function initSchemaInfo()
{ {
if (!$this->branchSupported()) { 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 { } else {
$query = "SELECT branch, version FROM schema_version WHERE domain = ? ORDER BY branch"; $query = "SELECT branch, version FROM schema_version WHERE domain = ? ORDER BY branch";
} }
...@@ -101,8 +102,8 @@ class DBSchemaVersion implements SchemaVersion ...@@ -101,8 +102,8 @@ class DBSchemaVersion implements SchemaVersion
$statement->execute([$this->domain]); $statement->execute([$this->domain]);
$versions = $statement->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE); $versions = $statement->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP | PDO::FETCH_UNIQUE);
if ($versions) { foreach ($versions as $branch => $version) {
$this->versions = array_map('intval', $versions); $this->versions[$branch] = (int) $version;
} }
} }
...@@ -114,7 +115,7 @@ class DBSchemaVersion implements SchemaVersion ...@@ -114,7 +115,7 @@ class DBSchemaVersion implements SchemaVersion
*/ */
public function get($branch = 0) public function get($branch = 0)
{ {
return $this->versions[$branch ?: $this->branch]; return $this->versions[$branch];
} }
/** /**
...@@ -125,7 +126,7 @@ class DBSchemaVersion implements SchemaVersion ...@@ -125,7 +126,7 @@ class DBSchemaVersion implements SchemaVersion
*/ */
public function set($version, $branch = 0) public function set($version, $branch = 0)
{ {
$this->versions[$branch ?: $this->branch] = (int) $version; $this->versions[$branch] = (int) $version;
if (!$this->branchSupported()) { if (!$this->branchSupported()) {
$query = "INSERT INTO schema_version (domain, version) $query = "INSERT INTO schema_version (domain, version)
...@@ -143,7 +144,7 @@ class DBSchemaVersion implements SchemaVersion ...@@ -143,7 +144,7 @@ class DBSchemaVersion implements SchemaVersion
$statement = DBManager::get()->prepare($query); $statement = DBManager::get()->prepare($query);
$statement->execute([ $statement->execute([
$this->domain, $this->domain,
$branch ?: $this->branch, $branch,
$version $version
]); ]);
} }
...@@ -164,14 +165,18 @@ class DBSchemaVersion implements SchemaVersion ...@@ -164,14 +165,18 @@ class DBSchemaVersion implements SchemaVersion
if ($result && $result->rowCount() > 0) { if ($result && $result->rowCount() > 0) {
$backported_migrations = [ $backported_migrations = [
20200306, 20200306, 20200713, 20200811, 20200909, 20200306, 20200713, 20200811, 20200909, 20200910,
20200910, 20201002, 20201103, 202011031, 20210317 20201002, 20201103, 202011031, 20210317
]; ];
$query = "DELETE FROM schema_versions $query = "DELETE FROM schema_versions
WHERE domain = 'studip' AND version in (?)"; WHERE domain = 'studip' AND version in (?)";
$db->execute($query, [$backported_migrations]); $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 ( $query = "CREATE TABLE schema_version (
domain VARCHAR(255) COLLATE latin1_bin NOT NULL, domain VARCHAR(255) COLLATE latin1_bin NOT NULL,
branch VARCHAR(64) COLLATE latin1_bin NOT NULL DEFAULT '0', branch VARCHAR(64) COLLATE latin1_bin NOT NULL DEFAULT '0',
...@@ -187,6 +192,22 @@ class DBSchemaVersion implements SchemaVersion ...@@ -187,6 +192,22 @@ class DBSchemaVersion implements SchemaVersion
$query = "DROP TABLE schema_versions"; $query = "DROP TABLE schema_versions";
$db->exec($query); $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]);
}
} }
} }
} }
...@@ -194,16 +194,17 @@ class Migrator ...@@ -194,16 +194,17 @@ class Migrator
public function migrateTo($target_version) public function migrateTo($target_version)
{ {
$migrations = $this->relevantMigrations($target_version); $migrations = $this->relevantMigrations($target_version);
$target_branch = $this->schema_version->getBranch();
# you're on the right version # you're on the right version
if (empty($migrations)) { 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; return;
} }
$this->log( $this->log(
'Currently at version %d. Now migrating %s to %d.', 'Currently at version %d. Now migrating %s to %d.',
$this->schema_version->get(), $this->schema_version->get($target_branch),
$this->direction, $this->direction,
max($this->target_versions) max($this->target_versions)
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment