Skip to content

Commit 727d9cd

Browse files
committed
Merge pull request #8 from apeckham/master
Commits to increase test coverage
2 parents 136ad18 + ef9951e commit 727d9cd

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

lib/mysql2psql/postgres_db_writer.rb

+1-14
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,7 @@ def write_indexes(table)
102102
next if index[:primary]
103103
unique = index[:unique] ? "UNIQUE " : nil
104104

105-
#MySQL allows an index name which could be equal to a table name, Postgres doesn't
106-
indexname = index[:name]
107-
if indexname.eql?(table.name)
108-
indexnamenew = "#{indexname}_index"
109-
puts "WARNING: index \"#{indexname}\" equals table name. This is not allowed by postgres and will be renamed to \"#{indexnamenew}\""
110-
indexname = indexnamenew
111-
end
112-
113-
if @conn.server_version < 80200
114-
@conn.exec("DROP INDEX #{PGconn.quote_ident(indexname)} CASCADE;") if exists?(indexname)
115-
else
116-
@conn.exec("DROP INDEX IF EXISTS #{PGconn.quote_ident(indexname)} CASCADE;")
117-
end
118-
@conn.exec("CREATE #{unique}INDEX #{PGconn.quote_ident(indexname)} ON #{PGconn.quote_ident(table.name)} (#{index[:columns].map {|col| PGconn.quote_ident(col)}.join(", ")});")
105+
@conn.exec("CREATE #{unique}INDEX ON #{PGconn.quote_ident(table.name)} (#{index[:columns].map {|col| PGconn.quote_ident(col)}.join(", ")});")
119106
end
120107

121108

test/integration/convert_to_db_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_datetime_defaults
102102

103103
def test_index_conversion
104104
result = exec_sql_on_psql('SELECT pg_get_indexdef(indexrelid) FROM pg_index WHERE indrelid = \'test_index_conversion\'::regclass').first
105-
assert_equal "CREATE UNIQUE INDEX test_index_conversion_index ON test_index_conversion USING btree (column_a)", result["pg_get_indexdef"]
105+
assert_equal "CREATE UNIQUE INDEX test_index_conversion_column_a_idx ON test_index_conversion USING btree (column_a)", result["pg_get_indexdef"]
106106
end
107107

108108
def test_foreign_keys

0 commit comments

Comments
 (0)