# DB / App Best Practice

**URL:** <https://www.ruby-forum.com/t/db-app-best-practice/174451>\
**Category:** Rails\
**Created:** [August 26, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/db-app-best-practice/174451 "2009-08-26T22:09:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@brianp](https://www.ruby-forum.com/u/brianp)\
**Post date:** [August 26, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/db-app-best-practice/174451/1 "2009-08-26T22:09:14Z")

</div>

Hey Everyone.

Just wondering what I should do in regard to how much data (what type  
of data) to store in the db.

If I have a table of cars:

## –cars– id - PK type color

In regards to the color is it best to just store a value for the color  
as an int, the string of the color (ie. “blue”) or have a second table  
to represent the colors ie:

## –cars– id - PK type color\_id - FK

## –colors– id - PK value

I can see some ups and downs to both. Not having the colors table  
means the colors/values need to be maintained in the app itself. Where  
as having the colors in the table can make it easier to expand etc.

I’ve run into this kind of problem on a few occasions and am wondering  
what way to go about it.

On the same idea but may have a completely different answer as this is  
a bit more specific. When it comes to users. Is it a good idea to  
store ALL users (including admin) in the same user table? Separated by  
an account\_type (ie. reg\_user, admin\_user). If this is the case should  
I make an account\_type table to store account types?

Thanks for the input,  
brianp

---

<div class="post-metadata">

**Author:** ![brianp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@brianp](https://www.ruby-forum.com/u/brianp)\
**Post date:** [August 27, 2009, 10:20am UTC](https://www.ruby-forum.com/t/db-app-best-practice/174451/2 "2009-08-27T10:20:19Z")

</div>

For admins and users, I would keep them both in the same table with a  
role field to differentiate them. It really depends on your security  
requirement and if admins and users login using the same  
authentication mechanism. A role table for lookup is required.

For colors, MYSQL allows an ENUM type for a field. But it isn’t  
directly supported by Rails.

> <https://stackoverflow.com/questions/693928/how-replacecreate-an-enum-field-on-rails-2-0-migrations>

might help if you are using MYSQL and want to modify Rails to support  
it. For your particular case, you need to take a call based on data  
volume and the attributes you want to segregate. Maybe a cars table  
and a car\_attributes table with something more than just a color in  
there.
