Search code examples
ruby-on-railsrubygemssurveyor-gem

conflict model names in surveyor gem


I'm about installing surveyor gem, i followed the instructions there but when i executed this line to install the gem components:

script/rails generate surveyor:install

I got these conflicts

    conflict  db/migrate/20120716110951_create_questions.rb
Overwrite /home/saka/modares/db/migrate/20120716110951_create_questions.rb? (enter "h" for help) [Ynaqdh] h

I know that the problem is these conflict model names in the gem and in the existing application as i already have a model named Question.

How to resolve this conflict?


Solution

  • This behavior is a result of an design decision in surveyor. We would like to allow people to run rails generate surveyor:install every time they upgrade surveyor, and get new migrations and changed files. The generator finds migrations with the same class name, preserves the timestamp, and presents the conflict to the user if it is different. One thing that may affect your decision moving forward is that if you do maintain your existing create_questions migration, you'll have to contend with this conflict every time you upgrade surveyor. There are a few solutions:

    1. Surveyor could be changed to support name-spaced, configurable, or otherwise modifiable model names. This will most certainly take time, and there are currently no issues for this feature (but feel free to add one).

    2. You could rename your migration and the generator will run. Remove the create_questions and add_correct_answer_id_to_questions migrations, and remove questions from the add_api_ids migration. Make sure your question model matches the surveyor question model as documented in the wiki (there's no guarantee we'll keep the diagram in sync). More definitively, you may create a blank rails project, add surveyor, run the generator and migrations, and then look at db/schema.rb. You'll have to keep your question model in sync with surveyor's manually.

    3. You could rename your model. If it has existing functionality besides surveyor's, you'll probably want to go this route anyway.