Reputation: 1797
I need to create a new field in a database table. Then I run the following:
sequelize migration:create
A new file called
DATETIME_unnamed-migration.js
is created.
I open that file and write this in the up-function:
queryInterface.addColumn(
'User',
'postcode',
Sequelize.STRING
)
I then run
sequelize db:migrate
The table User has now a new field called "postcode".
So what now? I have a file named
DATETIME_unnamed-migration.js
Next time I need to add a new field, what do I do? If I try to modify the file above and then run db:migrate again nothing happens. On the console I see:
No migrations were executed, database schema was already up to date.
So sequelize-cli doesn't care that one of my old migration files changed? Do I need to create a new migration-file every time I need to add new things in database schema? Then after a while the directory with migration files will be full. Is this the ordinary approach or am Imissing something?
Upvotes: 0
Views: 1358
Reputation: 56
With migrations you can transfer your existing database into another state and vice versa: Those state transitions are saved in migration files, which describe the way how to get to the new state and how to revert the changes in order to get back to the old state.
I believe that the idea of migration files is to keep track of changes and updates of database schema. So you will have to create a new migration file everytime you want to update your database schema.
Upvotes: 2