1

I am planning to use Postgres as my database and sequelize as my ORM framework one of my NodeJS project. I need your suggestion on how to accomplish database table changes in production enviroment.

For example , we deployed our version-1 application with some database schema. Later , there is a change in my schema in Version-2. Say one of the table is altered and few columns are dropped and few columns are added. Also one of the table itself is not required in Version-2.

In my production , I have some database with data. When I install Version-2 of my NodeJS application , I need to keep the old data as it is and apply the new database schema of Version-2.

How to achieve this , Let me point out some reference to this.

Thanks

1 Answer 1

1

Sequelize (or rather, sequelize-cli) has built in support for migrations.

You can write migrations using the Sequelize js api (e.g. queryInterface.dropColumn('users', 'address')) or write raw SQL and pass it to sequelize.query()

Sign up to request clarification or add additional context in comments.

4 Comments

Do I need to write my own script file to handle this case . "Sequelize" won't do it automatically?
If you have sequelize-cli installed you can have it generate migration skeletons for you (run sequelize db:migration:create) which you then modify to make the required database changes - is that what you're looking for?
Yes I want a kind of solution which auto generate migration script using the sequelize data model. Can you point me some reference page or suggest some solution?
I see what you mean now. I would also like to generate migrations from model definitions, but unfortunately it's not possible! Take a look at stackoverflow.com/questions/27835801/… for some workarounds and advice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.