Backfilling data in node.js

127 Views Asked by At

In Rails I'm using backfill gem to backfill data. Is there something similar in node.js? Not migration schema, but filling/populating data in existing tables. For example, when introducing new column we might want to populate it based on other column, or pre-commutate it's value. The closes I found is Sequelize seed

However, seeding is to insert new data, this could be also used for changing data. And it would be ideal to have an option to start backfill multiple times if needed (for example if we want to fix corrupt data)

We use Postgres DB by the way

Any recommendations?

Thanks

1

There are 1 best solutions below

0
Zegarek On

This sounds like a job for default, a generated column or a plain update. Problem is that default cannot reference other columns and a generated value cannot be inserted or updated to anything else. I think sequelize defaultValue is limited to what can be defined as SQL default.

You can define the column and let it get initialised with NULL values, update() non-selectively to set your starting default, and whenever you need to revert to that, you can add a where to the update in order to target the right record(s).

Model hooks could let you intercept new records (or any activity on them after they were created) and inject your default.