Wrong issue numbers when importing from GitHub

I’m using GitLab 7.11.4 installed with DigitalOcean 1-click install. When I imported my GitHub projects, the issues’ numbers where mixed up. From what I’ve noticed the issues where imported by date descending, so the last issue created is number #1. Now the commit messages lead to the wrong issues.

Have I done something wrong? I just hit the import button - not sure if there is something else to be done.

If this behavior is by design, can I access the database in order to update the issues’ numbers manually?

Thanks in advance

I found out how to connect to the database directly using:

su - gitlab-psql


/opt/gitlab/embedded/bin/psql gitlabhq_production

This will allow you to do manual queries in the database. Next is how to use a script to do changes for you.


In order to access the database from a script you’ll need to make it insecure for a while. Edit the file /var/opt/gitlab/postgresql/data/pg_hba.conf and set the method to trust. Then you can use a script like this:

import psycopg2
import sys
# Try to connect
    conn = psycopg2.connect("host='/tmp/' dbname='gitlabhq_production' user='gitlab'")
    print "I am unable to connect to the database."
#Get project_id
project_id = raw_input('Enter project_id: ')

cursor = conn.cursor()

# Get max iid from the project issues
cursor.execute("SELECT MAX(iid) AS iid FROM issues WHERE project_id = %s", (project_id, ))
max_iid = cursor.fetchone()
print "Max IID: ", max_iid[0]

cursor.execute("UPDATE issues SET iid = iid + %s WHERE project_id = %s", (max_iid[0], project_id))

# Loop issues, updating the iid
cursor.execute("SELECT id FROM issues WHERE project_id = %s order by iid asc", (project_id, ))
rows = cursor.fetchall()

current = max_iid[0]

print "\nUpdating to the correct iid: \n"
for row in rows:
    cursor.execute("UPDATE issues SET iid = %s WHERE id = %s AND project_id = %s", (current, row[0], project_id))
    print "   ID: ", row[0], " -> IID: ", current
    current -= 1
print "\nDone"

# Commit things

# Close

This script will invert the order of the issue numbers for the project. Don’t execute in a project you’re already using - only for recently imported projects. After executing return the postgresql configuration to peer map=gitlab.

1 Like

Yeap, the devs are aware from what I asked and plan to refine the importer in future versions. Cannot give you an ETA though :confused:

Thanks for providing a script!