# :has\_one and migrating production data base

**URL:** <https://www.ruby-forum.com/t/has-one-and-migrating-production-data-base/155182>\
**Category:** Rails\
**Created:** [December 9, 2008, 2:02am UTC](https://www.ruby-forum.com/t/has-one-and-migrating-production-data-base/155182 "2008-12-09T02:02:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 9, 2008, 2:02am UTC](https://www.ruby-forum.com/t/has-one-and-migrating-production-data-base/155182/1 "2008-12-09T02:02:00Z")

</div>

I am leery of migrating my perfectly stable and fine production data  
base.

But I need to add some customer info to my system.

I am adding a new model backed by a database for the new customer  
info.  
Thus I’m assuming that I won’t need to migrate the old database. The  
change is  
that there is a new database.

However the existing production database will need a ‘:has\_one’ for  
the new  
database.

This is the change I need to make to the production database of  
Orders.  
The new database will hold download links and passwords, for some  
orders, So I need the new database (Order\_Download) to contain the  
above fields (download\_link and password) plus the foreign key  
order\_id, and the old database (Orders)  
will contain an ‘:has\_one’ to associate it with Order\_Download.

So I have:

class Order \< ActiveRecord::Base  
has\_one: order\_download // NEW, ADDING TO PRODUCTION DATABASE

class OrderDownload \< ActiveRecord::Base // new database  
belongs\_to :order

The question is, can I just add this and nothing will break, nothing  
needs  
migrating, everything is cool?

Or am I changing the production database Orders with a new ‘:has\_one’  
which  
is going to require me to do something painful? Like migrate, yuck.

Sorry I’m a database newbie and I’d rather not mess with it.

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [December 9, 2008, 3:06am UTC](https://www.ruby-forum.com/t/has-one-and-migrating-production-data-base/155182/2 "2008-12-09T03:06:18Z")

</div>

On Mon, Dec 8, 2008 at 8:00 PM, minka [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> that there is a new database.  
> order\_id, and the old database (Orders)
> 
> The question is, can I just add this and nothing will break, nothing  
> needs  
> migrating, everything is cool?
> 
> Or am I changing the production database Orders with a new ‘:has\_one’  
> which  
> is going to require me to do something painful? Like migrate, yuck.
> 
> Sorry I’m a database newbie and I’d rather not mess with it.

I am still something of a newbie myself, but as I read the documentation  
(I  
wish I could give you a better link than "[http://api.rubyonrails.org/](http://api.rubyonrails.org/),  
search for “belongs\_to” 6 times), the model with the foreign key is the  
one  
that “belongs\_to” the the model that “has\_one” of the other model. See  
the  
section entitled “Is it a belongs\_to or has\_one association?”

Keeping in mind that I too am a newbie, I don’t think you will have to  
touch  
your existing database, (although you will want to modify your model  
with  
the “has\_one” attribute if you want to reach the corresponding entry in  
the  
new table.

Of course, you can (and should) copy your existing production database  
to  
your development database and verify that none of your changes affect  
the  
existing database.

hth…

–wpd
