0

So after alot of reading i found out that i dont need to plan my database ahead. I just start working on the application and do migrations on every change.

So for example if I decide to add something I add it via migration. Then on another migration I delete it for some reason. And in the end I decide to get it back. After a short time there will be a mess of migrations.

How do I keep track of them? Wouldnt be easier to think of the database structure in the first place?

Denny Mueller
  • 3,505
  • 5
  • 36
  • 67

2 Answers2

0

You can see your database structure inside db/schema.rb which will show you all the tables, columns and indexes currently in your app.

Not as helpful if you're constantly changing a column, but you can also run rake db:migrate:status which will output a list of all migrations, and tell you whether they've been run or not.

mind.blank
  • 4,820
  • 3
  • 22
  • 49
0

Rails way is to do everything via migrations. As per your scenario it would be like:

migration1 #add column A
migration2 #remove column A
migration3 #add column A again

It seems like there are lots of migrations, but in practical scenario it will keep your database changes clean. Because at any given time when you do:

rake db:migrate

Rails will run only the pending migrations.

And at any given time you will see the db/schema.rb file with all the migrates and latest migration number as the version.

Having said that, if you want to revert a migration there are commands like rollback commands. Read more about migrations here.

halfer
  • 19,824
  • 17
  • 99
  • 186
sameera207
  • 16,547
  • 19
  • 87
  • 152