Skip to content

Import all indexes including their names. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ 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.
- Preserve default values of boolean (originally `tinyint(1)`) columns.
- Import all indexes.
- Import index names.

How to use
----------
Expand All @@ -41,8 +41,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 @@ -181,15 +181,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 @@ -222,9 +230,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.