maxlapshin / mysql2postgres

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

`initialize': undefined method `connect' for PG:Module on OSX #80

Open nlively opened 9 years ago

nlively commented 9 years ago

I'm using ruby 1.9.3-p551 with RVM on an OSX Yosemite installation. Keep running into this error:

WARN: Unresolved specs during Gem::Specification.reset:
      postgres-pr (~> 0.6)
      activerecord (~> 3.2)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/myself/.rvm/gems/ruby-1.9.3-p551/gems/pg-0.18.2/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/myself/.rvm/gems/ruby-1.9.3-p551/gems/pg-0.18.2/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/connection.rb:46:in `initialize': undefined method `connect' for PG:Module (NoMethodError)
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/postgres_db_writer.rb:12:in `new'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysql2psql/postgres_db_writer.rb:12:in `initialize'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysqltopostgres.rb:49:in `new'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/lib/mysqltopostgres.rb:49:in `convert'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551@global/gems/mysqltopostgres-0.2.20/bin/mysqltopostgres:23:in `<top (required)>'
    from /Users/myself/.rvm/rubies/ruby-1.9.3-p551/bin/mysqltopostgres:23:in `load'
    from /Users/myself/.rvm/rubies/ruby-1.9.3-p551/bin/mysqltopostgres:23:in `<main>'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `eval'
    from /Users/myself/.rvm/gems/ruby-1.9.3-p551/bin/ruby_executable_hooks:15:in `<main>'

Never seen that error before this task I'm doing, and I can't seem to find it referenced online.

nlively commented 9 years ago

I've been continuing to research this and play around with the code. Seems like the problem goes away when the 'postgres-pr' gem is excluded from the Gemfile. Looks like these gems conflict in their definition of the PG namespace.

paazmaya commented 8 years ago

Can you create a Pull Request with the suggested fix?

ljlozano commented 8 years ago

+1, OSX, Yosemite, Ruby 2.1.7 / RVM

/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/liltomato/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/liltomato/.rvm/gems/ruby-2.1.7@global/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/liltomato/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `load'
    from /Users/liltomato/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `<main>'
    from /Users/liltomato/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `eval'
    from /Users/liltomato/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `<main>'
ideaoforder commented 8 years ago

+1

guillosaracco commented 8 years ago

+1, OSX, Yosemite, Ruby 2.1.7 / RVM

Any updates on this?

WARN: Unresolved specs during Gem::Specification.reset:
      test-unit (~> 2.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/Guillo/.rvm/gems/ruby-2.1.7/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/Guillo/.rvm/gems/ruby-2.1.7@global/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/Guillo/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `load'
    from /Users/Guillo/.rvm/rubies/ruby-2.1.7/bin/mysqltopostgres:23:in `<main>'
    from /Users/Guillo/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `eval'
    from /Users/Guillo/.rvm/gems/ruby-2.1.7/bin/ruby_executable_hooks:15:in `<main>'
nitsujri commented 8 years ago

+1, thanks for ths repo!

samstickland commented 8 years ago

I have a very similar issue on El Capitan

$ mysqltopostgres
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Users/samuelstickland/.rvm/gems/ruby-2.3.0/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/mysqltopostgres:23:in `load'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/mysqltopostgres:23:in `<main>'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/samuelstickland/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
lucandrade commented 8 years ago

Same here

$ mysqltopostgres
/Library/Ruby/Gems/2.0.0/gems/pg-0.18.4/lib/pg/connection.rb:230: warning: already initialized constant PGconn
/Library/Ruby/Gems/2.0.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:6: warning: previous definition of PGconn was here
/Library/Ruby/Gems/2.0.0/gems/pg-0.18.4/lib/pg/result.rb:26: warning: already initialized constant PGresult
/Library/Ruby/Gems/2.0.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:69: warning: previous definition of PGresult was here
/Library/Ruby/Gems/2.0.0/gems/mysqltopostgres-0.3.0/bin/mysqltopostgres:30:in `<top (required)>': '' does not exist (RuntimeError)
    from /usr/local/bin/mysqltopostgres:23:in `load'
    from /usr/local/bin/mysqltopostgres:23:in `<main>'
eniacization commented 8 years ago

I get the same error as lucandrade.

paazmaya commented 8 years ago

All I can say is that Pull Requests are more than welcome, as I do not have the resources for doing this at the moment

ritec commented 8 years ago

Did anyone ever figure this out? Getting same error as @lucandrade

brettimus commented 8 years ago

I followed the advice of removing references to the postgres-pr gem, since I'm using MRI. (This fix won't work for JRUBY users, sowwy.)

See: https://github.com/brettimus/mysql2postgres/tree/issue_80_workaround

After hitting issue #73, was able to get it to work. (This comment had the fix that did the trick for me.)

Worth noting: if you run the command from your terminal, the "environment" defaults to "development". I.e., the script will try to access the postgres database defined under the development key in your config file. If you want to change that, you should specify a RAILS_ENV variable.

E.g., running

RAILS_ENV=production mysqltopostgres config.yml

Would use the "production" database defined below:

mysql2psql:
  mysql:
    <<: *pii

  destination:
    production:
      <<: *production