Skip to content

Commit

Permalink
Import all indexes including their names.
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed May 9, 2015
1 parent 6f9cf5a commit 6c72c45
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 63 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ GitLab.
- Guard against replacing '0000-00-00 00:00:00' inside SQL text fields.
- Replace all MySQL zero-byte string literals `\0`. This is safe as of GitLab
6.8 because the GitLab database schema contains no binary columns.
- Add the `add_index_statements.rb` script to recreate indices dropped by
`db_converter.py`.
- Never set 'NOT NULL' constraints on datetimes.
- Drop sequences before creating them.
- Import all indexes.
- Import index names.

How to use
----------
Expand All @@ -40,8 +40,6 @@ Next, load your new dump into a fresh PostgreSQL database using:

`psql -f databasename.psql -d gitlabhq_production`

Finally, [recreate the indexes for your GitLab version](http://doc.gitlab.com/ce/update/mysql_to_postgresql.html#rebuild-indexes).

More information
----------------

Expand Down
14 changes: 0 additions & 14 deletions add_index_statements.rb

This file was deleted.

28 changes: 18 additions & 10 deletions db_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse(input_filename, output_filename):
creation_lines = []
enum_types = []
foreign_key_lines = []
fulltext_key_lines = []
index_lines = []
sequence_lines = []
cast_lines = []
num_inserts = 0
Expand Down Expand Up @@ -171,15 +171,23 @@ def parse(input_filename, output_filename):
elif line.startswith("CONSTRAINT"):
foreign_key_lines.append("ALTER TABLE \"%s\" ADD CONSTRAINT %s DEFERRABLE INITIALLY DEFERRED" % (current_table, line.split("CONSTRAINT")[1].strip().rstrip(",")))
foreign_key_lines.append("CREATE INDEX ON \"%s\" %s" % (current_table, line.split("FOREIGN KEY")[1].split("REFERENCES")[0].strip().rstrip(",")))
elif line.startswith("UNIQUE KEY \""):
index_name = line.split('"')[1].split('"')[0]
index_columns = line.split("(")[1].split(")")[0]
index_lines.append("CREATE UNIQUE INDEX \"%s\" ON %s (%s)" % (index_name, current_table, index_columns))
elif line.startswith("UNIQUE KEY"):
creation_lines.append("UNIQUE (%s)" % line.split("(")[1].split(")")[0])
index_columns = line.split("(")[1].split(")")[0]
index_lines.append("CREATE UNIQUE INDEX ON %s (%s)" % (current_table, index_columns))
elif line.startswith("KEY \""):
index_name = line.split('"')[1].split('"')[0]
index_columns = line.split("(")[1].split(")")[0]
index_lines.append("CREATE INDEX \"%s\" ON %s (%s)" % (index_name, current_table, index_columns))
elif line.startswith("KEY"):
index_columns = line.split("(")[1].split(")")[0]
index_lines.append("CREATE INDEX ON %s (%s)" % (current_table, index_columns))
elif line.startswith("FULLTEXT KEY"):

fulltext_keys = " || ' ' || ".join( line.split('(')[-1].split(')')[0].replace('"', '').split(',') )
fulltext_key_lines.append("CREATE INDEX ON %s USING gin(to_tsvector('english', %s))" % (current_table, fulltext_keys))

elif line.startswith("KEY"):
pass
index_lines.append("CREATE INDEX ON %s USING gin(to_tsvector('english', %s))" % (current_table, fulltext_keys))
# Is it the end of the table?
elif line == ");":
output.write("CREATE TABLE \"%s\" (\n" % current_table)
Expand Down Expand Up @@ -212,9 +220,9 @@ def parse(input_filename, output_filename):
for line in sequence_lines:
output.write("%s;\n" % line)

# Write full-text indexkeyses out
output.write("\n-- Full Text keys --\n")
for line in fulltext_key_lines:
# Write indexes out
output.write("\n-- Indexes --\n")
for line in index_lines:
output.write("%s;\n" % line)

# Finish file
Expand Down
35 changes: 0 additions & 35 deletions index_create_statements.rb

This file was deleted.

0 comments on commit 6c72c45

Please sign in to comment.