oaken icon indicating copy to clipboard operation
oaken copied to clipboard

A way to enforce a order that seeds are loaded?

Open marcelolx opened this issue 6 months ago • 4 comments

For example, with fixtures if on one fixture I say that it is associated with an organization, Rails magically runs the organization fixture first (I guess?), but that doesn't happen with oaken which makes it quite hard to even try to migrate an existing suite relying on fixtures because you have to organize the folders in a way that the seeds runs in the correct order.

Example

# test/fixtures/users.yml
josh:
  name: Josh

# test/fixtures/organizations.yml
acme:
  name: Acme Inc.

# test/fixtures/organization_memberships.yml
josh_at_acme:
  user: josh
  organization: acme

I know this example might be simple, and the obvious answer is, "You can do it all in a single seed file, following the right sequence", but that gets quite messy when your data model is way bigger and more interconnected than a simple user having a membership on an organization.

Another helpful example is an organization that can have multiple Plans. With fixtures, you would have both in the same folder level, but with Oaken, we might not be able to do that because the seed file that has the plans might run before the one that sets up the organization and users — now imagine this for 100 different models that are all interconnected in some way, the folder structures needed to guarantee the correct order would be painful.

marcelolx avatar Aug 22 '24 19:08 marcelolx