# BOOK: "Pro Active Record" - Chapter 3

**URL:** <https://www.ruby-forum.com/t/book-pro-active-record-chapter-3/158384>\
**Category:** Rails\
**Created:** [January 22, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/book-pro-active-record-chapter-3/158384 "2009-01-22T19:30:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [January 22, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/book-pro-active-record-chapter-3/158384/1 "2009-01-22T19:30:12Z")

</div>

Good morning,

I’m reading the book “Pro Active Record” by Marshall, Pytel, & Yurek.  
Currently stuck on chapter 3. I’m using [Ruby 1.8.6 \<2007-09-24\>  
patchlevel 111] & [Rails 2.1.1].

Chapter 3 discusses migrations. In the example provided in the book,  
the test scripts are created and ran outside of a Rails project. The  
instructions say to create a database.yml file, migrate.rb script, &  
database migration script. When ‘ruby migrate.rb’ is ran from ms-dos,  
it should create the schema table in my database and also create the  
cows table described in the migration script.

Here’s my issue, only the ‘schema\_migrations’ table is created in the  
database. The cows table described in the migration isn’t created in  
the database.

Please review the source below and let me know if you see anything out  
of place. If you have time, try running the scripts yourself to see if  
you have better results.

Thank you,

Frank

* * *

## database.yml:

development: # developer’s workstation  
adapter: mysql  
encoding: utf8  
database: project\_development  
host: localhost  
username: project  
password: pass

* * *

## migrate.rb

require “rubygems”  
gem “activerecord”  
require “active\_record”

if ARGV[0] =~ /VERSION=\d+/  
version = ARGV[0].split(’=’)[1].to\_i  
else  
version = nil  
end

@logger = Logger.new $stderr  
ActiveRecord::Base.logger = @logger  
ActiveRecord::Base.colorize\_logging = false

@config = YAML.load\_file(File.join(File.dirname( **FILE** ),  
‘database.yml’))  
ActiveRecord::Base.establish\_connection(@config[“development”])  
ActiveRecord::Migrator.migrate("", version)

* * *

## 001\_create\_cows.rb

class CreateCows \< ActiveRecord::Migration  
def self.up  
create\_table :cows do |t|  
t.column :name, :string  
t.column :breed, :string  
t.column :born\_on, :datetime  
t.column :milkable, :boolean  
end  
end

def self.down  
end

end

---

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [January 23, 2009, 1:16am UTC](https://www.ruby-forum.com/t/book-pro-active-record-chapter-3/158384/2 "2009-01-23T01:16:06Z")

</div>

On 22 Jan 2009, at 18:30, Frank K. wrote:

> database migration script. When ‘ruby migrate.rb’ is ran from ms-dos,  
> you have better results.

Looks like the migration code has changed a little.

> ActiveRecord::Migrator.migrate(".", version)

should work better.

Fred

---

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [January 23, 2009, 1:30pm UTC](https://www.ruby-forum.com/t/book-pro-active-record-chapter-3/158384/3 "2009-01-23T13:30:28Z")

</div>

Thank you Frederick. I wish I was still running these scripts outside  
of a RoR project. I gave up and created a dummy RoR app just so that I  
could do ‘rake db:migrate’.

Frederick C. wrote:

> On 22 Jan 2009, at 18:30, Frank K. wrote:
> 
> > database migration script. When ‘ruby migrate.rb’ is ran from ms-dos,  
> > you have better results.
> 
> Looks like the migration code has changed a little.
> 
> > ActiveRecord::Migrator.migrate(".", version)
> 
> should work better.
> 
> Fred
