Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #9759

Closed
Open
Created Oct 22, 2015 by Administrator@rootOwner

Broken migration db/migrate/20140416074002_add_index_on_iid.rb

Created by: 4picht

If the iid column is NULL for all issues (as it is, if you upgrade from a really old version), the fix for this migration actually deletes all issues except one random one per project. Also this migration does not work with the current version of active record, because AR does no longer return an array but a relation object in line 20.

This patch solves it for me, it would be better though to fix the earlier migrations, that add the fields, and make them populate the field.

diff --git a/db/migrate/20140416074002_add_index_on_iid.rb b/db/migrate/20140416074002_add_index_on_iid.rb
index 85269e2..4b4e37b 100644
--- a/db/migrate/20140416074002_add_index_on_iid.rb
+++ b/db/migrate/20140416074002_add_index_on_iid.rb
@@ -12,12 +12,18 @@ end

 class RemoveDuplicateIid
   def self.clean(klass, project_field = 'project_id')
+    nulls = klass.find_by_sql("SELECT * FROM #{klass.table_name} WHERE iid IS NULL")
+    nulls.each do |n|
+      n.set_iid
+      n.update_attribute :iid, n.iid
+    end
+
     duplicates = klass.find_by_sql("SELECT iid, #{project_field} FROM #{klass.table_name} GROUP BY #{project_field}, iid HAVING

     duplicates.each do |duplicate|
       project_id = duplicate.send(project_field)
       iid = duplicate.iid
-      items = klass.of_projects(project_id).where(iid: iid)
+      items = klass.of_projects(project_id).where(iid: iid).to_a

       if items.size > 1
         puts "Remove #{klass.name} duplicates for iid: #{iid} and project_id: #{project_id}"
Assignee
Assign to
Time tracking