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
Automated migration setup #897
Conversation
cc @coyotte508 might be worth taking a look if you have time, especially the following files:
|
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.
A bit of an issue with spaces with continued availability - the old app can run for a bit after migrations are run.
So ideally, migrations happen in two steps: a first PR is deployed that fills in the new data (eg search tokens), and a second PR is deployed with the migration + the feature visible for users.
Just a bit of a process to think of
Reduce timer for lock
If we deploy the data generation before deploying the feature, isn't there a gap between the two deployments where new documents would be missed ? Not sure if I got it correctly 😅 |
What I mean:
So:
|
Co-authored-by: Mishig <[email protected]>
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.
lgtm !
This PR adds a check on startup that runs migrations if needed.
How it works
Each migration is defined by it's.
_id
field which is unique and hardcoded. When the migration is applied we add it to the"migrationResults"
collections, so we can check if it has already been run. Each migration is wrapped in a transaction to ensure consistency.The migration check runs at the top-level of
hooks.server.ts
to ensure it only runs once on startup.DB Locks
Because we can have multiple instances of chat-ui running against a single DB we need to ensure we have a lock before running migrations.
The code for lock related operations is under lock.ts with the associated unit-tests.
How it works:
semaphore
collection with a unique index on keysinsertOne
, if it fails to insert then a lock must already exist (see acquireLock)updatedAt
field with a TTL index for mongo to discard if it times outMigrations
You can find an example migration here
Migrations can have both
up
(required) anddown
(optional) methods (though we don't use thedown
method for now) and optionally they can also set:We should port the migration from #841 when merging this PR.