# Help me understand migrations movie

**URL:** <https://www.ruby-forum.com/t/help-me-understand-migrations-movie/50893>\
**Category:** Rails\
**Created:** [December 22, 2005, 10:24am UTC](https://www.ruby-forum.com/t/help-me-understand-migrations-movie/50893 "2005-12-22T10:24:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhubarb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rhubarb](https://www.ruby-forum.com/u/rhubarb)\
**Post date:** [December 22, 2005, 10:24am UTC](https://www.ruby-forum.com/t/help-me-understand-migrations-movie/50893/1 "2005-12-22T10:24:41Z")

</div>

I’m somewhat of a newbie - played with recent versions of rails a few  
mths ago, but have decided to start from scratch with 1.0.  
I want to build my new db as much as possible with migrations, so I  
watched DHH’s migrations movie from [rubyonrails.org](http://rubyonrails.org).

A few things confuse me:

1. He generates the model (“post”) before running rake db\_schema\_dump.  
Is that necessary or just a preference?

2. He says that running db\_schema\_dump will create not only the schema  
file, but the database. He’s using sqllite, I’m using MySQL, and it  
didnt work for me. That is, rake db\_schema\_dump issued an error  
complaining that the database didnt exist.

I created the database in the MySQL console, tried again and it worked.  
So question: Does db\_schema\_dump only create the db for sqllite, or did  
DHH misspeak, or did I misunderstand?

1. DHH then goes into the autogenerated schema.rb and adds code to  
create the tables. He notes the warning about not modifying the  
autogenerated file, but says “we’re going to run with scissors here”.  
I appreciate what he’s doing here, but what concerns me is, is this the  
way it’s meant to be done? Or is it some shortcut for a quick video?

I’m not criticizing here, I’m just trying to start a project from  
scratch and follow the simplest path.

Is creating the tables in the db console before runing db\_schema\_dump  
the proper way?  
Is db\_schema\_dump really only meant to be used do dump out the schema  
later?  
Should I be creating migrations files to start creating my tables, and  
not be using db\_schema\_dump first?

Also another startup question: I’m starting my project, and I’ll be  
messing with the table definitions a bit. But I have no data yet and no  
real need for migrations - this is all preliminary stuff - so should I  
create migrations each time for each new column, etc, or “hard code” it  
all in schema.rb, or do it all in the MySQL console.

thanks for any advice offered

---

<div class="post-metadata">

**Author:** ![rhubarb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rhubarb](https://www.ruby-forum.com/u/rhubarb)\
**Post date:** [December 22, 2005, 10:45am UTC](https://www.ruby-forum.com/t/help-me-understand-migrations-movie/50893/2 "2005-12-22T10:45:52Z")

</div>

I would pretty much ignore schema.rb, and just generate new migration  
files, then run “rake migrate” to update your database.

Schema.rb basically is all your migrations in one file, so good for when  
you distribute/deploy an application.

Schema.rb gets created when you run db\_schema\_dump or gets created  
automatically if you un-comment “config.active\_record.schema\_format =  
:ruby” in enviroment.rb.

As far as I am aware you have to create a database first then run rake  
migrate. I guess you could have the database created automatically if  
you add create\_database to the first migration file, but I have not  
tried it because some developers may have different database names in  
database.yml depending on their local setup, so there is no need to  
force a database name, only table/field names.

If your messing with tables to start with you could do it without  
migrations using command line or GUI but when you are done do a  
db\_schema\_dump, and copy the code in schema.rb to your first migration  
file.

I hope that helps…

Kris.

rover rhubarb wrote:

> 1. He generates the model (“post”) before running rake db\_schema\_dump.  
> Is that necessary or just a preference?
> 
> 2. He says that running db\_schema\_dump will create not only the schema  
> file, but the database. He’s using sqllite, I’m using MySQL, and it  
> didnt work for me. That is, rake db\_schema\_dump issued an error  
> complaining that the database didnt exist.
> 
> I created the database in the MySQL console, tried again and it worked.  
> So question: Does db\_schema\_dump only create the db for sqllite, or did  
> DHH misspeak, or did I misunderstand?
> 
> 1. DHH then goes into the autogenerated schema.rb and adds code to  
> create the tables. He notes the warning about not modifying the  
> autogenerated file, but says “we’re going to run with scissors here”.  
> I appreciate what he’s doing here, but what concerns me is, is this the  
> way it’s meant to be done? Or is it some shortcut for a quick video?
> 
> I’m not criticizing here, I’m just trying to start a project from  
> scratch and follow the simplest path.
> 
> Is creating the tables in the db console before runing db\_schema\_dump  
> the proper way?  
> Is db\_schema\_dump really only meant to be used do dump out the schema  
> later?  
> Should I be creating migrations files to start creating my tables, and  
> not be using db\_schema\_dump first?
> 
> Also another startup question: I’m starting my project, and I’ll be  
> messing with the table definitions a bit. But I have no data yet and no  
> real need for migrations - this is all preliminary stuff - so should I  
> create migrations each time for each new column, etc, or “hard code” it  
> all in schema.rb, or do it all in the MySQL console.
> 
> thanks for any advice offered

---

<div class="post-metadata">

**Author:** ![rhubarb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rhubarb](https://www.ruby-forum.com/u/rhubarb)\
**Post date:** [December 22, 2005, 11:09am UTC](https://www.ruby-forum.com/t/help-me-understand-migrations-movie/50893/3 "2005-12-22T11:09:04Z")

</div>

Rover,

If you haven’t already, explore the 2 resources at:  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/ActiveRecordMigration)

Migrations are brilliant.  
When creating a project from scratch, all you have to do on the DB  
server is create an empty DB. Everything - ? - else is done though  
migrations.

I must confess I also found the screencast a little confusing. I watched  
it anyway, and learned a few things.

For example, uncomment this line in ‘environment.rb’  
config.active\_record.schema\_format = :ruby

=\> after each migration, ‘schema.rb’ will be updated and show you all  
the structures you have created in one place. Invaluable.

There are still a few bugs though.

Alain
