Commit 5e20b0a73c51f8d480a94a384301135e765b0ad6
Exists in
spb-stable
and in
2 other branches
Merge branch 'new_index_converter' into 'master'
New index converter
Showing
1 changed file
with
33 additions
and
6 deletions
Show diff stats
doc/update/mysql_to_postgresql.md
| @@ -34,21 +34,48 @@ The lanyrd database converter script does not preserve all indexes, so we have | @@ -34,21 +34,48 @@ 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 non-omnibus installations | ||
| 39 | + | ||
| 40 | +On non-omnibus 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 versions older than 6.9, 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 | +# Download schema.rb.bundled if necessary | ||
| 72 | +test -e /opt/gitlab/embedded/service/gitlab-rails/db/schema.rb.bundled || 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 | ||
| 73 | + | ||
| 74 | +# Generate add_index.rb | ||
| 75 | +/opt/gitlab/embedded/bin/ruby add_index_statements.rb /opt/gitlab/embedded/service/gitlab-rails/db/schema.rb.bundled > add_index.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 | +# Create the indexes |
| 78 | +/opt/gitlab/bin/gitlab-rails runner 'eval $stdin.read' < add_index.rb | ||
| 52 | ``` | 79 | ``` |
| 53 | 80 | ||
| 54 | ## Converting a GitLab backup file from MySQL to Postgres | 81 | ## Converting a GitLab backup file from MySQL to Postgres |