zerosand1s
zerosand1s

Reputation: 750

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 -

Thanks.

Upvotes: 1

Views: 1187

Answers (1)

Mikael Lepistö
Mikael Lepistö

Reputation: 19728

I usually don't write down functions at all and just leave them empty.

I never rollback migrations and if I want to get to earlier DB state I just restore whole DB from backups.

If I just want to put unique constraint back, I will write another up migration which fixes duplicate rows and then adds unique constraint back.

I know that many people is using rollback between tests to reset DB, but that is really slow way to do it.

Upvotes: 1

Related Questions