Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
f6828d15
Commit
f6828d15
authored
3 years ago
by
Elmar Ludwig
Committed by
Jan-Hendrik Willms
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/migrations/DBSchemaVersion.php
+16
-28
16 additions, 28 deletions
lib/migrations/DBSchemaVersion.php
lib/migrations/Migrator.php
+1
-1
1 addition, 1 deletion
lib/migrations/Migrator.php
with
17 additions
and
29 deletions
lib/migrations/DBSchemaVersion.php
+
16
−
28
View file @
f6828d15
...
@@ -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
=
"
D
ELE
TE
FROM schema_versions
$query
=
"
S
ELE
CT 1
FROM schema_versions
WHERE domain = 'studip' AND version
in (?)
"
;
WHERE domain = 'studip' AND version
= ?
"
;
$db
->
execute
(
$query
,
[
$backported_migrat
ion
s
]);
$result
=
$db
->
fetchOne
(
$query
,
[
$old_vers
ion
]);
// drop migrations with ir
re
g
ul
ar numbers
if
(
$
re
s
ul
t
)
{
$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
]);
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
lib/migrations/Migrator.php
+
1
−
1
View file @
f6828d15
...
@@ -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'
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment