Skip to content
Snippets Groups Projects
Commit 110a5f9c authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Merge branch 'fix-migration' into 'master'

Fix ci_projects migration by using the value only from latest row [ci skip]

This is needed, because for some projects we have duplicate ci_projects.
This was introduced by lack of DB uniqueness on ci_projects.gitlab_id.

The MR fixes edge case by selecting value from latest.

/cc @yorickpeterse 

Fixes: gitlab-org/gitlab-ce#4123


See merge request !2133
parents 61a1bdd7 e136a976
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -26,7 +26,8 @@ class MigrateCiToProject < ActiveRecord::Migration
 
def migrate_project_column(column, new_column = nil)
new_column ||= column
subquery = "SELECT ci_projects.#{column} FROM ci_projects WHERE projects.id = ci_projects.gitlab_id"
subquery = "SELECT ci_projects.#{column} FROM ci_projects WHERE projects.id = ci_projects.gitlab_id " \
'ORDER BY ci_projects.updated_at DESC LIMIT 1'
execute("UPDATE projects SET #{new_column}=(#{subquery}) WHERE (#{subquery}) IS NOT NULL")
end
 
Loading
Loading
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