Moving Migrations to their Own Files
Hi folks,
I’m working on adding Migrations using the Stateful Migrations Component and have got everything working. I got a note in code review from @Eva that it’d be good if we could split up our migrations into their own individual files, but when I attempted to do that, I started getting Convex errors.
Is there a supported way to use the migrations component and also have each migration live in its own typescript file (e.g.
/convex/migrations/setQuestsUpdatedTimestamp.ts
)?GitHub
GitHub - get-convex/migrations: Convex Migrations Component for tra...
Convex Migrations Component for tracking and running stateful migrations - get-convex/migrations
GitHub
chore: Create Migration for Quests.updatedAt in preparation for mak...
What changed?
Created a setQuestsUpdatedTimestamp migration that sets the updatedAt to now for all quests where it was undefined.
Before:
During:
After:
Progress on #393.
Why?
So that we can ...
6 Replies
cc @Ian supporting migrations defined in multiple files in a directory sounds like a good idea.
Hi @mb, it doesn't look like this component supports multiple files directly right now, but I think you can define a migration in a separate file and then re-export it in your
migrations.ts
file. Have you tried this already? If not give it a shot and let me know how it goeswhen you say re-export it, what do you mean exactly?
@mb It's already supported unless I'm missing something. From the docs:
Examples below are assuming the code is inconvex/migrations.ts
. This is not a requirement. If you want to use a different file, make sure to change the examples below frominternal.migrations.*
to your new file name, likeinternal.myFolder.myMigrationsFile.*
or CLI arguments likemigrations:*
tomyFolder/myMigrationsFile:*
.
oh maybe that’s the step i was missing, thanks @Ian. I’ll give that a shot
One idea is to group migrations by what table they convert, or release version, or some organization where you'd want to see all the possibly related changes. One per file is fine, but might get unwieldly down the line
Ian's suggestion sounds better than mine, but by re-export I meant export the function from file XYZ and then import and re-export it in
migrations.ts
like:
export { myMigration } from './migrations/XYZ
. However, since it looks like multiple files is supported, that isn't necessary!