Thursday, 18 May 2017

How to write down function in migration file (knex.js)

I have been wondering about how to write down function in migration file. Ideally, it should be exactly opposite of what we are doing in up method. Now suppose I wrote up function to drop unique constraint on a column, added some new rows(having duplicate data) to a table and now I want to rollback the migration. Ideally, I would write down method to add a unique constraint again on the column but migration would not rollback as a table now contains duplicate data. So my questions are -

  • What to do in such a situation?
  • How to write down function in migrations?
  • Can I keep the down function blank in such a situations?

Thanks.



via Harshal Gangurde

No comments:

Post a Comment