Reputation: 710
Hey in my rails app i want to store wether and app is on a Production environment or Development. In my activerecord migration i set the field for :environment ad an integer, 0 is development and 1 is production. Then when i want to use this as plain text i have a helper method that converts this to text from the 0 and 1. Should i store this value in my database as an integer or plain text? I would like to use the most efficient way be cause i would like to make a method like if twitter.is_development()
do this.
Upvotes: 0
Views: 959
Reputation: 3308
I would name the column as "env" and use "production", "development" and "testing" as values to indicate the current env.
You cant predict the future and storing the raw value helps you in many places, like lets say, I call a rake task like,
"rake product:update_price RAILS_ENV=production",
then I would use the value retrieved from the env column without any logic, like
"rake product:update_price RAILS_ENV=#{env}",
so that if its development, production or testing it will use accordingly.
Check this, Rails.env vs RAILS_ENV, maybe you dont need to store anything at all.
Upvotes: 1
Reputation: 943
It would make more sense to store it as an integer because they represent numbers. If you wanted to use text then "true" and "false" would be more suitable.
Whatever you decide you won't be able to measure the difference in performance. Choose what is easiest to understand and maintain. "Premature optimization is the root of all evil".
Upvotes: 1