maxlapshin / mysql2postgres

Mysqldump, writing in postgresql format
MIT License
711 stars 156 forks source link

Some problems while migrating a database #13

Closed johbo closed 8 years ago

johbo commented 14 years ago

I just did a migration from a mysql database and had some issues. I tried some simple fixes, but I must admit, that I do not speak any Ruby ;-)

So the attached diff may inspire you to find a real solution. The problems seemed to be realted to enum columns which had some default values.

diff --git a/mysql2psql b/mysql2psql
index 1ad9a04..a035133 100755
--- a/mysql2psql
+++ b/mysql2psql
@@ -60,7 +60,7 @@

 require 'rubygems'
 require 'mysql'
-gem "pg"
+# gem "pg"
 require 'pg'
 require 'yaml'

@@ -336,10 +336,10 @@ class PostgresWriter < Writer
     when "text"
       "text"
     when /^enum/
-      default = " DEFAULT #{column[:default].nil? ? 'NULL' : column[:default]}" if default
+      default = " DEFAULT '#{column[:default].nil? ? 'NULL' : column[:default]}'" if default
       enum = column[:type].gsub(/enum|\(|\)/, '')
       max_enum_size = enum.split(',').map{ |check| check.size() -2}.sort[-1]
-      "character varying(#{max_enum_size}), check( #{column[:name]} in (#{enum}))"
+      "character varying(#{max_enum_size})" #, check( #{column[:name]} in (#{enum}))"
     else
       puts "Unknown #{column.inspect}"
       column[:type].inspect
tardate commented 14 years ago

I think this should be fixed as of http://github.com/maxlapshin/mysql2postgres/commit/973b1f11e317a3342c6d2c9230f642f8d1a25923

paazmaya commented 8 years ago

Closing as an old issue, that would seem to be out of date. Feel free to re-open and update with comments aganst the master branch.