Forum: Ruby on Rails BOOK: "Pro Active Record" - Chapter 3

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.
7f81419ef29a86176e43845d955085bb?d=identicon&s=25 Frank Kany (frank_programmer)
on 2009-01-22 19:30
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-23 01:16
(Received via mailing list)
On 22 Jan 2009, at 18:30, Frank Kany 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
7f81419ef29a86176e43845d955085bb?d=identicon&s=25 Frank Kany (frank_programmer)
on 2009-01-23 13:30
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 Cheung wrote:
> On 22 Jan 2009, at 18:30, Frank Kany 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
This topic is locked and can not be replied to.