-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update seed to use export default function() instead of top-level await #10334
Conversation
🦋 Changeset detectedLatest commit: 7f0741c The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I'd like to discuss the problems this solves before we accept this change, as this feels like (albeit slight) DX downgrade for something that feels like an implementation detail / bug. Can you explain the problems you've seen from the existing seeding method? Have you run into bugs or are these theoretical problems? |
Yes, happy to reiterate @matthewp! Problem: both users and integrations are able to seed the database. Trouble is how we handle changes to the user's seed file in development. When the user's seed file changes, we tear down the whole database, recreate, and rerun the user seed file. Trouble is, we also need to rerun the integration seed file to get the db back to its initial state. Since we use top-level await, and imports are cached, we cannot easily rerun the integration seed file. Speaks to a general problem: top level await = can only run module once (easily). One fix would be to stop tearing down the whole database, instead just tearing down user-managed tables to leave integration tables in-tact. The other fix is to add a wrapper function to ensure seed files can be rerun in development. We chose the latter because we're worried other problems could be caused in the future where rerunning the seed file is the only fix. I agree with you on ergonomics though. Curious which side you lean towards. |
Real problems when introducing integration support. Here’s the rundown:
So far so good. This gets wonky once you need to support multiple seed files (i.e. integrations):
I shared a few options with Ben yesterday:
I’ll also note that with option 2, it could still lead to bad DX: while the obvious use case for an integration is to take care of seeding itself, you might also use an integration to separate out multiple seed files that are user-editable. In that case, the broken flow described above could also happen where the integration seed reloads successfully and the user seed doesn’t re-run. |
👿 FINE 😀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default
initely ready to merge
Changes
Changes db seed file format to require exporting a default function instead of running the seed file at the top level:
Before
After
This makes re-running a seed file much less complex — no need to invalidate a module to get its top-level expressions to re-run.
Also avoids risks of bundlers one day having issues with top-level
await
.This PR updates the seed files in test fixtures to the new format.
Testing
astro dev
locally to check behaviour is as expected.Docs
Will need to update the WIP docs to show this new format, cc @sarah11918