Commit b7de9de4d2682a7af66e1fd8db5ec0a3fcf8980e

Authored by Jacob Vosmaer
1 parent 260c877c

Omnibus instructions for re-adding indexes

Showing 1 changed file with 32 additions and 6 deletions   Show diff stats
doc/update/mysql_to_postgresql.md
@@ -34,21 +34,47 @@ The lanyrd database converter script does not preserve all indexes, so we have @@ -34,21 +34,47 @@ The lanyrd database converter script does not preserve all indexes, so we have
34 to recreate them ourselves after migrating from MySQL. It is not necessary to 34 to recreate them ourselves after migrating from MySQL. It is not necessary to
35 shut down GitLab for this process. 35 shut down GitLab for this process.
36 36
  37 +
  38 +### For source installations
  39 +
  40 +On source installations (distributed using Git) we retrieve the index
  41 +declarations from version control using `git stash`.
  42 +
37 ``` 43 ```
38 # Clone the database converter on your Postgres-backed GitLab server 44 # Clone the database converter on your Postgres-backed GitLab server
39 cd /tmp 45 cd /tmp
40 git clone https://github.com/gitlabhq/mysql-postgresql-converter.git 46 git clone https://github.com/gitlabhq/mysql-postgresql-converter.git
41 47
42 -# Stash changes to db/schema.rb to make sure we can find the right index statements  
43 cd /home/git/gitlab 48 cd /home/git/gitlab
  49 +
  50 +# Stash changes to db/schema.rb to make sure we can find the right index statements
44 sudo -u git -H git stash 51 sudo -u git -H git stash
45 52
46 -# Generate the `CREATE INDEX CONCURRENTLY` statements based on schema.rb  
47 -cd /tmp/mysql-to-postgresql-converter  
48 -ruby index_create_statements.rb /home/git/gitlab/db/schema.rb > index_create_statements.psql 53 +# Generate add_index.rb
  54 +ruby /tmp/mysql-postgresql-converter/add_index_statements.rb db/schema.rb > /tmp/mysql-postgresql-converter/add_index.rb
  55 +
  56 +# Create the indexes
  57 +sudo -u git -H bundle exec rails runner -e production 'eval $stdin.read' < /tmp/mysql-postgresql-converter/add_index.rb
  58 +```
  59 +
  60 +### For omnibus-gitlab installations
  61 +
  62 +On omnibus-gitlab we need to get the index declarations from a file called
  63 +`schema.rb.bundled`. For older versions, we need to download the file.
  64 +
  65 +```
  66 +# Clone the database converter on your Postgres-backed GitLab server
  67 +cd /tmp
  68 +/opt/gitlab/embedded/bin/git clone https://github.com/gitlabhq/mysql-postgresql-converter.git
  69 +cd /tmp/mysql-postgresql-converter
  70 +
  71 +# Generate add_index.rb
  72 +/opt/gitlab/embedded/bin/ruby add_index_statements.rb /opt/gitlab/embedded/service/gitlab-rails/db/schema.rb.bundled > add_index.rb
  73 +
  74 +# If schema.rb.bundled does not exist, download it as follows, then try generating add_index.rb again
  75 +sudo /opt/gitlab/embedded/bin/curl -o /opt/gitlab/embedded/service/gitlab-rails/db/schema.rb.bundled https://gitlab.com/gitlab-org/gitlab-ce/raw/v6.9.1/db/schema.rb
49 76
50 -# Execute the SQL statements against the GitLab database  
51 -sudo -u git psql -f index_create_statements.psql -d gitlabhq_production 77 +/opt/gitlab/bin/gitlab-rails runner 'eval $stdin.read' < add_index.rb
52 ``` 78 ```
53 79
54 ## Converting a GitLab backup file from MySQL to Postgres 80 ## Converting a GitLab backup file from MySQL to Postgres