graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Apply seeds in cli-migrations v3

Open preetjdp opened this issue 2 years ago • 1 comments

Is your proposal related to a problem?

The CLI Migrations docker image currently only applies the migrations and the metadata, the proposal is for it to also apply the seeds when the directory is present

Describe the solution you'd like

  • If the hasura-seeds directory is mounted to the container, apply the seeds

If the feature is approved, would you be willing to submit a PR?

Yes, already on it

preetjdp avatar Dec 12 '21 08:12 preetjdp

The reason why this might be a bad idea is, that seeds are currently stateless, as opposed to migrations. ie migrations are in a way idempotent, so a cli-migrations container can be restarted multiple times in its lifetime since the migrations "state" is persisted.

But on the other hand, seeds are not handled in a similar fashion, so unless the user writes seeds as idempotent SQL a similar behaviour cannot be achieved.

For example, if I've some seeds to apply from my cli-migrations image, I'll start my container and the image will apply my seeds. Now let's say I spin up another replica of this image and that container will also try to apply the same seeds and will probably fail since the entities already exist in the database. This happens because the "state" in which seeds are applied is not persisted.

Please add your comments/thoughts/suggestions

scriptonist avatar Aug 02 '22 10:08 scriptonist

May be this could do the trick, but I am not sure! Inside your docker-compose file add this line into your Hasura CLI Migrations service: command: sh -c "hasura-cli seed apply"

aimproxy avatar Jan 03 '23 20:01 aimproxy

that seeds are currently stateless

perhaps the lack of any migrations in the db can be used as a herustic to decide if seeds should be run or not? Alternatively, seeds can be written idempotently - this can be a limitation for those wanting seeds to be applied automatically.

mbrevda avatar Mar 12 '24 17:03 mbrevda