Hello everyone, I’m new in Rails and have a question about migration.
Hello everyone, I’m new in Rails and have a question about migration. I have a simple rails application, which has a database with tables.
1. If I need to rename/delete/add column to the table in db should I create 3 migrations or it can be one big migration?
2. My directory db/migrate contains now 10 migrations and I think it is not good, what should I do with them?
Could you, please,
1. If I need to rename/delete/add column to the table in db should I create 3 migrations or it can be one big migration?
2. My directory db/migrate contains now 10 migrations and I think it is not good, what should I do with them?
Could you, please,
No any search results
You already invited:
4 Answers
JavierPons
Upvotes from: Emmanuel 、Tom
2. This is fine.
There are a lot of resources on the internet that you can find on the topic of rails migrations. I would recommend reading the Rails guides :
allian
Upvotes from: Emmanuel 、Tom
re: renaming - sometimes it’s easier just to delete the column and readd the new column
however, if you’re not worried about current data (this is a new app) often times I’ll completely delete an old migration and replace it with a new one if I’ve changed my mind on how the data is structured
so, let’s say you already created a migration for the product table - if you’ve decided you actually needed other columns in it, if you haven’t already deployed the app, go ahead and just 1) modify the migration to add the other columns or 2) delete it and create a new one that is structured the way you want
migrations are handled in the sort order - so if you create a new migration and it has the same “serial” then it will run in the same order as before. This is mainly important if you have modifying migrations or have foreign keys where order is important
Practice
Upvotes from: Emmanuel
Emmanuel
Upvotes from: