Forum: Ruby on Rails Migration doesn't load data. How to debug a migration?

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.
Ea94dbb5d740e9d4adc6200f9c563452?d=identicon&s=25 Yitzhak Bar Geva (yitzhakbg)
on 2007-01-02 16:53
We're learning Rails from the 2nd edition of Agile Web development with
Rails under Ubuntu Edgy.
I messed up the Ruby and Gem environment but managed to put the pieces
together. However, there is one outstanding problem:
When running the migrations, they all work, except that the one which
loads data (couldn't attach, theres a bug on the server) does not load
the data. before the environment got messed up, it did work OK. It's
funny, because when we run the app. from the browser, data is entered
and stored in the database all right. There is no indication in the log
files that anything is amiss. Simply the data isn't written into the DB.
Wanted to know if anyone has a hint. Also, how can the migration be
debugged? It is run through Rake?
Thanks
8b22ad683842861ba91f68d5d32954db?d=identicon&s=25 Jason Norris (Guest)
on 2007-01-02 18:33
(Received via mailing list)
Sometimes when I can't figure out what is happening with the database, I
put a log on the database and tail it.
in /etc/my.cnf:
log             = /var/log/mysqld.log
This will get big fast in production but for development it helps.
Jason
Ea94dbb5d740e9d4adc6200f9c563452?d=identicon&s=25 Yitzhak Bar Geva (yitzhakbg)
on 2007-01-02 18:43
Jason Norris wrote:
> Sometimes when I can't figure out what is happening with the database, I
> put a log on the database and tail it.
> in /etc/my.cnf:
> log             = /var/log/mysqld.log
> This will get big fast in production but for development it helps.
> Jason

I looked there (I also tried with Sqlite - can't find it's log file),
but saw nothing relevant. That's why I wanted to try using the debugger.
It's weird. It worked before I screwed up the Ruby environment. After i
restored the Ruby environment, everything works OK, including my other
migrations 9which don't load data. Loading data also works OK, through
the web interface of the application. Only loading of data through the
migration doesn't work.
here's the migration (there's a bug on this forum when trying to attach
a file):
#---
# Excerpted from "Agile Web Development with Rails, 2nd Ed."
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book
information.
#---

class AddTestData < ActiveRecord::Migration
  def self.up

    Product.create(:title => 'Pragmatic Project Automation',
    :description =>
    %{<p>
       <em>Pragmatic Project Automation</em> shows you how to improve
the
       consistency and repeatability of your project's procedures using
       automation to reduce risk and errors.
      </p>
      <p>
        Simply put, we're going to put this thing called a computer to
work
        for you doing the mundane (but important) project stuff. That
means
        you'll have more time and energy to do the really
        exciting---and difficult---stuff, like writing quality code.
      </p>},
    :image_url =>   '/images/auto.jpg',
    :price => 29.95)


    Product.create(:title => 'Pragmatic Version Control',
      :description =>
      %{<p>
         This book is a recipe-based approach to using Subversion that
will
         get you up and running quickly---and correctly. All projects
need
         version control: it's a foundational piece of any project's
         infrastructure. Yet half of all project teams in the U.S. don't
use
         any version control at all. Many others don't use it well, and
end
         up experiencing time-consuming problems.
      </p>},
    :image_url => '/images/svn.jpg',
    :price => 28.50)

    # . . .


    Product.create(:title => 'Pragmatic Unit Testing (C#)',
    :description =>
    %{<p>
        Pragmatic programmers use feedback to drive their development
and
        personal processes. The most valuable feedback you can get while
        coding comes from unit testing.
      </p>
      <p>
        Without good tests in place, coding can become a frustrating
game of
        "whack-a-mole." That's the carnival game where the player
strikes at a
        mechanical mole; it retreats and another mole pops up on the
opposite side
        of the field. The moles pop up and down so fast that you end up
flailing
        your mallet helplessly as the moles continue to pop up where you
least
        expect them.
      </p>},
    :image_url => '/images/utc.jpg',
    :price => 27.75)


  end

  def self.down
    Product.delete_all
  end
end
1eca6b18b0f4cc804ae1c10547685e2c?d=identicon&s=25 jman (Guest)
on 2007-01-03 00:31
I'm having the same exact problem. I downloaded the same code and
migration won't work. I dropped all my data and raked it again and still
nothing.

> Only loading of data through the
> migration doesn't work.
> here's the migration (there's a bug on this forum when trying to attach
> a file):
> #---
> # Excerpted from "Agile Web Development with Rails, 2nd Ed."
> # We make no guarantees that this code is fit for any purpose.
> # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book
> information.
> #---
Ea94dbb5d740e9d4adc6200f9c563452?d=identicon&s=25 Yitzhak Bar Geva (yitzhakbg)
on 2007-01-03 01:07
jman wrote:
> I'm having the same exact problem. I downloaded the same code and
> migration won't work. I dropped all my data and raked it again and still
> nothing.
>
>> Only loading of data through the
>> migration doesn't work.
>> here's the migration (there's a bug on this forum when trying to attach
>> a file):
>> #---
>> # Excerpted from "Agile Web Development with Rails, 2nd Ed."
>> # We make no guarantees that this code is fit for any purpose.
>> # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book
>> information.
>> #---

Nice to know that I'm in good company. Know what? I'm going to post this
on the one of the relevant Pragmatic Programmers forums/wikis.
94cc3e46cfc5bc361e409e2e884ecfa4?d=identicon&s=25 Drew Olson (Guest)
on 2007-01-04 22:42
Yitzhak Bar Geva wrote:
> Nice to know that I'm in good company. Know what? I'm going to post this
> on the one of the relevant Pragmatic Programmers forums/wikis.

I was having the same problems as well and was able to fix them by
updating rails to the absolute newest version, which is the release
candidate of Rails 1.2.0. You need this version of Rails in order to
follow the examples in the book.

-Drew
Ea94dbb5d740e9d4adc6200f9c563452?d=identicon&s=25 Yitzhak Bar Geva (yitzhakbg)
on 2007-01-04 22:56
Drew Olson wrote:
> Yitzhak Bar Geva wrote:
>> Nice to know that I'm in good company. Know what? I'm going to post this
>> on the one of the relevant Pragmatic Programmers forums/wikis.
>
> I was having the same problems as well and was able to fix them by
> updating rails to the absolute newest version, which is the release
> candidate of Rails 1.2.0. You need this version of Rails in order to
> follow the examples in the book.
>
> -Drew

Thanks Drew,
In my case, it didn't solve the problem. I'll check again to make sure
it was the latest version. In any case, I was wondering how one goes
about debugging a migration.
Yitzhak
2fa160ca7a85db04bcb02a13f92bfd92?d=identicon&s=25 Nathan Nobbe (quickshiftin)
on 2014-09-22 09:50
Checkout this article about enhancing the migrations system to work well
with multiple lines of development in version control!

https://quickshiftin.com/blog/2014/09/pragmatic-da...
This topic is locked and can not be replied to.