YANQ (yet another newbie question) - changes to the database

1 view
Skip to first unread message

Andrew

unread,
Nov 11, 2009, 12:19:25 PM11/11/09
to Nashville Ruby Group
Hello again,

If we've met you know I'm new to Ruby and Rails. I've made quite some
progress over the past several weeks. Thanks to everyone who has
helped me with this journey.

On this question, I'm looking for clarification that I'm doing the
right thing.

I'm working on a *very* basic app and I try to put what I have learned
to application.

Starting out I created my scaffold using this command:
: ruby script/generate nifty_scaffold Post title:string
description:string post:string

Now, I realize that I should have done this:
: ruby script/generate nifty_scaffold Post title:string
description:string post:text

Why? The post needs to be like the message box here in Google
Groups. A bunch of text.

So, what I'm looking at is the process to change the post from a
string to a text.

Is this the best approach?

-- run: rake db:migrate VERSION=0
-- delete the related rb file from \db\migrate
-- run : ruby script/generate nifty_scaffold Post title:string
description:string post:text
-- modify the /views/posts erb files, changing f.text_field to
f.memo_field (haven't figured out exactly what it is suppose to be
yet)

Thanks again,
Andrew


Andrew Rodriguez

unread,
Nov 11, 2009, 12:48:08 PM11/11/09
to Nashville Ruby Group
Ok, I see that I would need to do the following.

ruby script/generate remove_post_from_Post post:string
ruby script/generate add_post_to_Post post:text

Correct?

Daniel Nelson

unread,
Nov 11, 2009, 12:59:23 PM11/11/09
to nashville-...@googlegroups.com
Hi Andrew,

Until I deploy a project, I avoid making migrations to adjust the
database structure every time it is tweaked. Instead, I go into the
original migration, change the data type, and then rebuild the
database (either by migrating to version 0 and back as you indicate,
or by rake db:drop, rake db:create, rake db:migrate).

This keeps the original migrations accurate, which I find helpful, as
I often refer to those migrations to tell me what data is available to
a particular class. After an application in in production, this isn't
feasible because your database has valuable data, and it probably
wouldn't work in a team setting, but I find it useful so long as the
flexibility is available to you.

Cheers,

Daniel

frank_kany

unread,
Nov 11, 2009, 1:03:57 PM11/11/09
to Nashville Ruby Group
Does running "ruby script/generate add_post_to_Post post:text " create
a new migration and automatically run it?

I've been manually creating migrations then running "rake db:migrate".
> > Andrew- Hide quoted text -
>
> - Show quoted text -

deadwards

unread,
Nov 12, 2009, 9:52:57 AM11/12/09
to Nashville Ruby Group
I usually follow Daniel's method of just editing the original
migrations and running "rake db:migrate:reset" to redo the whole db
from the migrations. There's no use creating un-needed migrations
unless you're worried about losing data in the db.

Frank: Running "ruby script/generate add_post_to_Post post:text" will
generate the migration and add the line to insert the new row, but
will NOT automatically run the migration, you still have to do that
yourself.

Andrew Rodriguez

unread,
Nov 12, 2009, 10:38:18 AM11/12/09
to nashville-...@googlegroups.com
So, what do you do after you deploy?

Daniel Nelson

unread,
Nov 12, 2009, 11:17:38 AM11/12/09
to nashville-...@googlegroups.com
On Thu, Nov 12, 2009 at 9:38 AM, Andrew Rodriguez
<andrew...@gmail.com> wrote:
> So, what do you do after you deploy?

When in production with real data, I use migrations.

-Daniel

Reply all
Reply to author
Forward
0 new messages