small medium large xlarge

Generic-user-small
30 Sep 2011, 02:16
Jason Hsu (12 posts)

Through chapter 9, I saved my work with the following git commands entered from the depot directory: git add . git commit -a

After deleting everything in the depot directory, I was able to restore everything with the following commands: git reset –hard (sha1sum) rake db:migrate rake db:seed rails server -d

But starting in chapter 10, this wasn’t enough. There must be something that chapter 10 had me change that takes place OUTSIDE the depot directory. What is it? Has ANYONE here managed to properly save and restore everything using Git through chapter 10 and beyond?

When I entered “rake db:migrate”, the command gets ABORTED. The error message is:

WARNING: Global access to Rake DSL methods is deprecated. Please include … Rake::DSL into classes and modules which use the Rake DSL methods. WARNING: DSL method Depot::Application#task called at /var/lib/gems/ 1.8/gems/railties-3.0.5/lib/rails/application.rb:214:in `initialize_tasks’ == AddQuantityToLineItems: migrating ========================================= – add_column(:line_items, :quantity, :integer, {:default=>1}) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: line_items: ALTER TABLE “line_items” ADD “quantity” integer DEFAULT 1

Tasks: TOP => db:migrate (See full trace by running task with –trace)

But when I entered “rake db:seed”, I’m told that I have pending migrations and need to enter “rake db:migrate”. The message I get is:

WARNING: Global access to Rake DSL methods is deprecated. Please include … Rake::DSL into classes and modules which use the Rake DSL methods. WARNING: DSL method Depot::Application#task called at /var/lib/gems/ 1.8/gems/railties-3.0.5/lib/rails/application.rb:214:in `initialize_tasks’ You have 4 pending migrations: 20110211000004 AddQuantityToLineItems 20110920153246 CreateCarts 20110920153347 CreateLineItems 20110921012016 CombineItemsInCart Run “rake db:migrate” to update your database then try again.

Yes, I have been able to save my work using VirtualBox snapshots, which further leads me to suspect that chapter 10 had me change something outside the depot directory. However, VirtualBox snapshots do NOT work with a team. Unlike Git, VirtualBox does not offer seamless integration with other people’s work.

Samr_small_pragsmall
30 Sep 2011, 16:19
Sam Ruby (634 posts)

Has ANYONE here managed to properly save and restore everything using Git through chapter 10 and beyond?

I have.

You have 4 pending migrations: 20110211000004 AddQuantityToLineItems 20110920153246 CreateCarts 20110920153347 CreateLineItems 20110921012016 CombineItemsInCart

Question: how did AddQuantityToLineItems get a timestamp that is before CreateLineItems? Rename db/migrate/20110211000004_add_quantity_to_line_items.rb to db/migrate/20110921012017_add_quantity_to_line_items.rb and try again.

Generic-user-small
30 Sep 2011, 21:01
Jason Hsu (12 posts)

I copied the code files from the online depot and removed the version created from the rake db:migrate commands. Maybe that was my mistake.

Samr_small_pragsmall
30 Sep 2011, 22:56
Sam Ruby (634 posts)

If you ran db:migrate then copied the file, it would have worked that one time. Rails keeps track of which migrations have been applied and will only apply the new one.

When you deleted the database, you deleted this information too. Rails then attempted to apply all of the migrations in date order. The error you saw was due to an attempt to add a quantity row to a table that had yet to be created, due to the migrations being run out of order.

If you restore your VirtualBox snapshot and delete db/development.db, and then attempt to run db:migrate you should see the same failure.

You must be logged in to comment