Call to DataMapper.auto_upgrade! doesn't return

37 views
Skip to first unread message

Nikhil Prabhakar

unread,
Apr 5, 2012, 9:15:07 AM4/5/12
to datam...@googlegroups.com
Hi,
 I'm trying to setup a sinatra app on production server. In production environment, call to DataMapper.auto_upgrade! does not return. MySQL is running on a different server and I can connect to it via mysql command line as well as mysql gem. In an irb session I'm doing following steps to debug:

require 'rubygems'
require 'data_mapper'
require 'app/models/contact'
require 'environment'
DataMapper.setup(:default, Environment.get_db_conn_hash('production'))
DataMapper.auto_upgrade! # This call doesn't return.

Regards,
nipra

Dan Kubb (dkubb)

unread,
Apr 7, 2012, 1:04:42 AM4/7/12
to datam...@googlegroups.com
Hi Nipra,


require 'rubygems'
require 'data_mapper'
require 'app/models/contact'
require 'environment'
DataMapper.setup(:default, Environment.get_db_conn_hash('production'))
DataMapper.auto_upgrade! # This call doesn't return.

It sounds like there might be a circular reference somewhere that DataMapper is getting hung up on and never exiting from.

The first thing I would suggest doing is calling DataMapper.finalize before auto-upgrating, but after declaring your models. One convention I often use is DataMapper.finalize.auto_upgrade! which ensures finalization is performed at the last possible minute before migrating. The actual step of finalization ensures all the inferred properties are added to the models, and that the models themselves are in a "final" state where all primary and foreign keys are known to the system.

After you've done this, if it still never exits, we should attempt to isolate the model, properties and relationships to something as small as possible that can still reproduce the problem. I would suggest removing models, relationships and properties (trying to cut things down by 50% each time, kind of like a binary search) until you get to a small repro. It *looks* like you only have one model, but it's hard to know for sure from a few require statements, so I'm giving you instructions that would apply to 1 or more models.

Once you have a reliable reproduction, I would suggest putting it in a single executable file. If you are able to share this with the list, feel free to post a gist to the mailing list and we can look further. If for some reason you can't share it in public, but you feel comfortable sharing it with me privately feel free to email me the code so I can try it out here. If neither is possible, perhaps you can try to "anonymize" the code with some simple domain (Blog/Article/Comment, or Customer/Order/Item for example) where the problem still occurs.

It can sometimes be difficult to debug DataMapper issues only because everyone has different domains and approaches which are not always familiar to me. Sometimes people post huge snippets of code and expect that I can pick out the 1 error in 500 lines of unfamiliar code, which is pretty much impossible given my time constraints. However, by minimizing the code to *just* what is necessary to repro it reliably can make a huge difference in my ability to help.

In fact I would bet that most of the time if you go through this process you'll be able to identify the problem on your own. Often it's something you've introduced, or perhaps a typo, or maybe it leads you to the area in DM where the bug occurs.

-- 

Thanks,

Dan
Reply all
Reply to author
Forward
0 new messages