anlek / mongify

Mongify allows you to map your data from a sql database and into a mongodb document database.
http://github.com/anlek/mongify
MIT License
317 stars 82 forks source link

Having trouble with the Mongify sync command #109

Closed Xan1912 closed 5 years ago

Xan1912 commented 8 years ago

I have followed the necessary steps to sync the database. But still I am facing this error. Can you please help me out here with a clear description about how the 'sync' command works? Thanks.

meghdut@MS:~$ mongify sync datab.config nian.rb /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql_adapter.rb:308:in query': Mysql::Error: Unknown column 't.updated_at' in 'where clause': SELECT t.* FROM nian t, __mongify_sync_helper__ u WHERE t.updated_at > u.last_updated_at AND u.table_name = 'nian' (ActiveRecord::StatementInvalid) from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql_adapter.rb:308:inblock in exec_without_stmt' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in block in log' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22.2/lib/active_support/notifications/instrumenter.rb:20:ininstrument' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in log' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql_adapter.rb:307:inexec_without_stmt' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql_adapter.rb:290:in exec_query' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/mysql_adapter.rb:430:inselect' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in select_all' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22.2/lib/active_record/connection_adapters/abstract/query_cache.rb:63:inselect_all' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/database/sql_connection.rb:108:in select_by_query' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/translation/sync.rb:61:inblock in sync_data' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/translation/sync.rb:58:in each' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/translation/sync.rb:58:insync_data' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/translation/sync.rb:29:in sync' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/cli/command/worker.rb:71:inexecute' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/lib/mongify/cli/application.rb:28:in execute!' from /home/meghdut/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongify-1.2.4/bin/mongify:15:in<top (required)>' from /home/meghdut/.rbenv/versions/2.3.1/bin/mongify:23:in load' from /home/meghdut/.rbenv/versions/2.3.1/bin/mongify:23:in

'

anlek commented 7 years ago

Hey @Xan1912, Sorry for the late reply, I didn't write the sync method and was hoping that @hammady would respond but seems he hasn't had a chance. So here is my best guess in what's happening. It seems your table nian doesn't have an updated_at column (DateTime) which is needed to use with sync.

hammady commented 7 years ago

So sorry @Xan1912 for not handling this, @anlek is correct, as per the sync documentation, tables need to have an updated_at field for the sync to work. This is the only way sync knows what has changed in your data since the last sync command. This means that you also need to maintain this column by updating it to the current time whenever corresponding rows change.

oregondean commented 5 years ago

See this Mongify sync note