Forum: Ruby on Rails :has_one and migrating production data base

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
minka (Guest)
on 2008-12-09 03:02
(Received via mailing list)
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.
Patrick D. (Guest)
on 2008-12-09 04:06
(Received via mailing list)
On Mon, Dec 8, 2008 at 8:00 PM, minka <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/,
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
This topic is locked and can not be replied to.