I found out how to connect to the database directly using:
su - gitlab-psql
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:
# Try to connect
conn = psycopg2.connect("host='/tmp/' dbname='gitlabhq_production' user='gitlab'")
print "I am unable to connect to the database."
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
cursor.execute("UPDATE issues SET iid = iid + %s WHERE project_id = %s", (max_iid, 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
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, project_id))
print " ID: ", row, " -> IID: ", current
current -= 1
# Commit things
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.