Saturday, September 29, 2007

Notebook

Create a controller
ruby script/generate controller [controller_name]

Create a model
ruby script/generate model [mode_name]

Generate scaffolding code for an existing model
ruby script/generate scaffold [model_name] [controller_name]

Sunday, September 16, 2007

Dropping a database using rake db

I wanted to drop all tables in an existing database that was created using "rake db:migrate".
As I am very early in my development cycle, I wanted to make changes to the Create[Model].rb script itself rather than creating migrations with alter table commands.

Looked around for a few minutes and could not find anything reasonable.

Part of the reason probably was that I was not looking in the right places.

Anyways, eventually I found out the following:

1.) rake db generates a file called schema.db under your application/db folder.
2.) rake db maintains the current version number of your migrations in a table called schema_info in the database.

So, deleting the database and making rake re-create the tables was a matter of doing the following:

1.) drop table schema_info
2.) drop all my tables
3.) delete db/schema.db file
4.) Rerun rake db:migrate

Once I find the "right" way of doing things, I will post them back.