# Adding fields: same or separate table?

**URL:** <https://www.ruby-forum.com/t/adding-fields-same-or-separate-table/101095>\
**Category:** Engines\
**Created:** [February 4, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/adding-fields-same-or-separate-table/101095 "2006-02-04T21:14:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [February 4, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/adding-fields-same-or-separate-table/101095/1 "2006-02-04T21:14:45Z")

</div>

I’m just starting with the UserEngine on a new app. I’m going to have a  
bunch of other per-user data: phone number, AIM name, etc. Would it be  
better to add these as fields to the Users table, or to say that User  
:has\_one Profile, and put them in @user.profile? I’ve seen some people  
have trouble with has\_one syntax but I haven’t tried either way myself  
yet.

Any advantages/disadvantages to either approach? After noticing that  
the  
UserEngine down-migration deletes Users, I feel uncomfortable trusting  
it  
to leave my fields alone, but conceptually, these fields do belong to  
User.

Jay L.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [February 4, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/adding-fields-same-or-separate-table/101095/2 "2006-02-04T21:21:04Z")

</div>

The only situation where the user table would be deleted given a  
standard login/user engine setup would be if _you_ ran:

rake engine\_migrate ENGINE=login\_engine VERSION=0

… which is a pretty specific command. Because of this I’d say that  
it’s quite safe to place your extra data in the user table where it  
almost certainly belongs. There are probably many simpler and more  
likely ways to trash your database than this.

- james

On 2/4/06, Jay L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Jay L.
> 
> * * *
> 
> engine-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org)

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [February 4, 2006, 10:43pm UTC](https://www.ruby-forum.com/t/adding-fields-same-or-separate-table/101095/3 "2006-02-04T22:43:46Z")

</div>

On Sat, 4 Feb 2006 20:20:42 +0000, James A. wrote:

> The only situation where the user table would be deleted given a  
> standard login/user engine setup would be if _you_ ran:
> 
> rake engine\_migrate ENGINE=login\_engine VERSION=0

Ah, ok. I haven’t used migrations before, so I didn’t know what would  
have  
happened if, say, I’d had a pre-existing User table, and used migrations  
to  
add the new fields for LoginEngine and UserEngine. Looking more  
closely,  
I’m guessing I would have had an error - if my table already had a  
schema  
version, then 001\_initial\_schema wouldn’t have run, and if it had, it’s  
only creating tables, not adding fields…

This does make me think that some future version of Engines might want  
to  
handle just such a case - an engine that either creates its own table,  
or  
adds fields to an existing table. But that might be tricky since you  
can’t  
version parts of a table. Ah well. I guess that, in turn, depends on  
fancier inheritance in Rails.

Jay L.
