1

I need to add columns in my table tournament. My columns all correspond to a specific ranking and are of boolean type. My rankings name in real life look like : 40, 30/5, 30/4, 30/3 ect ect But I dont think I can writte a migration like this in rails :

class AddRankingsToTournaments < ActiveRecord::Migration
  def change 
    add_column :tournaments, :40, :boolean
    add_column :tournaments, :30/5, :boolean
    add_column :tournaments, :30/3, :boolean
  end
end

This would not be valid column names in rails and postgresql right ? What would be my best shot to rename my column names to something correct and still easy to indentify ?

David Geismar
  • 3,152
  • 6
  • 41
  • 80
  • Tricky one. How would you use this columns? Are planning on querying them? – BroiSatse Jul 16 '15 at 22:31
  • What about changing them to `forty` or using aliases in Rails model? – adamliesko Jul 16 '15 at 22:39
  • Not sure about Ruby, but you need to double-quote otherwise illegal identifiers in Postgres. Like `"30/5"`. Not that it would be a good idea to use such names to begin with - very error prone. Details: http://stackoverflow.com/a/13004915/939860, http://stackoverflow.com/a/20880247/939860 – Erwin Brandstetter Jul 16 '15 at 23:32
  • @BroiSatse yep I need to query them at some point to check if ```@tournament.40``` is true or false for example Yes I could change them to forty, thirtyfive... but I would lose the language & symbols specific to the business logic of my app ! – David Geismar Jul 16 '15 at 23:38

0 Answers0