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

NoMethod Error 'type_cast_from_database" - not processing date fields #101

Open firefli-uk opened 8 years ago

firefli-uk commented 8 years ago

Hi There, thanks for all your efforts with this project, will save me a ton of time migrating. ;) ... I'm struggling with an error. I'm not a ruby user so would appreciate some help figuring it out seems like something is missing.

/usr/local/lib/ruby/gems/2.2.0/gems/mongify-1.3.0/lib/mongify/database/column.rb:249:intype_cast': undefined method type_cast_from_database' for #<ActiveRecord::Type::DateTime:0x007f95f46b1188> (NoMethodError)

I'm going from MySql to MongoDB. It appears to be any time the translation comes across a date field it doesn't know what to do with it. In Mysql the format is set to "Date" and then

ruby -v ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]

Here's my gem list: activemodel (5.0.0) activerecord (5.0.0) activerecord-mysql2-adapter (0.0.3) activesupport (5.0.0) arel (7.0.0) bigdecimal (1.2.6) bson (1.12.5) bson_ext (1.12.5) concurrent-ruby (1.0.2) highline (1.7.8) i18n (0.7.0) io-console (0.4.3) json (1.8.1) minitest (5.4.3) mongify (1.3.0) mongo (1.12.5) mysql2 (0.4.4) power_assert (0.2.2) psych (2.0.8) rake (10.4.2) rdoc (4.2.0) test-unit (3.0.8) thread_safe (0.3.5) tzinfo (1.2.2)

Config file

table "advisers" do
    column "adviserid", :key
    column "advisername", :string
end

table "clientlinks" do
    column "linkid", :key 
    column "client1", :integer
    column "type1", :integer
    column "client2", :integer
    column "type2", :integer
end

table "clientnotes", :embed_in => 'clients', :on => 'clientid' do
    column "noteid", :key 
    column "clientid", :integer, :references => "clients"
    column "note", :text
    column "dateadded", :date
end

table "clients" do
    column "clientid", :key 
    column "adviserid", :integer, :references => "advisers"
    column "schemeid", :integer, :references => "schemed"
    column "title", :string
    column "initials", :string
    column "firstname", :string
    column "secondname", :string
    column "knownas", :string
    column "surname", :string
    column "dateofbirth", :date
    column "address1", :string
    column "address2", :string
        column "city", :string
    column "county", :string
    column "postcode", :string
    column "hometelno", :string
    column "worktelno", :string
    column "mobileno", :string
    column "email", :string
    column "maritalstatusid", :integer, :references => "marital status
    column "status", :string
    column "datelastseen", :date
end
```"
Rikcon commented 8 years ago

Same thing happened to me, googled a bit and found that this method was renamed in recent version of RoR. Not a ruby developer too ) All we can do is wait for maintainer to fix it in code.

GrahamW commented 8 years ago

I managed a quick fix to get it working.

The issue is that the gemspec asks for activerecord > 4.2, so 5.0.0 probably gets installed, which is incompatible with mongify atm.

I manually installed activerecord 4.2, then installed mongify: $ gem uninstall activerecord $ gem install activerecord --version '4.2' $ gem install mongify

Rikcon commented 8 years ago

@GrahamW Thanks ! Thought about it myself, but was too lazy to google it ) Your solution is working.

But it will be great if maintainer will fix it for 5.0.0 which installs "by default".

firefli-uk commented 8 years ago

Thanks @GrahamW and @Rikcon for pointing me in the right direction. It seems to be rather fussy with dependencies at the moment.

I followed @GrahamW instructions but then needed to install an older version of mysql2 gem to get it to work properly. I tried setting the adaptor in the config file back to 'mysql' didn't fix it immediately for me.

$ gem install mysql2 --version '0.3.18'

Thanks guys.