-
Notifications
You must be signed in to change notification settings - Fork 428
Auto migration #526
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
base: dev
Are you sure you want to change the base?
Auto migration #526
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
😱 Found 8 issues. Time to roll up your sleeves! 😱 🗒️ View all ignored comments in this repo
|
apps/backend/package.json
Outdated
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.
how will the new scripts work with source-of-truth? assumably we also have to update the new github workflows when we merge the branch? (just putting here as a reminder for when you merge branches)
apps/backend/.gitignore
Outdated
@@ -36,3 +36,5 @@ yarn-error.log* | |||
# typescript | |||
*.tsbuildinfo | |||
next-env.d.ts | |||
|
|||
src/auto-migrations/migration-files.tsx |
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.
can we put this in src/generated/auto-migrations or so?
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.
and then the .gitignore can be in src/generated like in the client library
await runQueryAndMigrateIfNeeded({ | ||
prismaClient, | ||
fn: async () => { | ||
await tx.$queryRaw(getMigrationCheckQuery()); | ||
}, | ||
}); | ||
|
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.
run when the prismaclient is created instead
}> { | ||
const migrationFiles = options.migrationFiles ?? MIGRATION_FILES; | ||
|
||
await acquireMigrationLock({ prismaClient: options.prismaClient }); |
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.
await acquireMigrationLock({ prismaClient: options.prismaClient }); | |
// TODO we should not acquire a lock if the migrations are already up-to-date, and at most once for every migration that is being applied. (right now, in a long-running migration which will cause many servers to restart, all those servers after the first one would queue up and lock one after the other just to see that we're already up-to-date and release the lock again. in the future, we could use a mix of shared and exclusive locks to make sure that only one client at a time attempts to get an exclusive lock, and if it fails to get that, goes back to acquiring a shared lock instead) | |
await acquireMigrationLock({ prismaClient: options.prismaClient }); |
would be better if we don't acquire a lock when all migrations are up-to-date, but I think we can just leave a todo here and worry later
-- Check if started_at exists and is within 10 seconds | ||
IF started_at_value IS NOT NULL AND started_at_value >= clock_timestamp() - INTERVAL '10 seconds' THEN | ||
RAISE EXCEPTION 'MIGRATION_IN_PROGRESS'; | ||
ELSIF started_at_value IS NOT NULL AND started_at_value < clock_timestamp() - INTERVAL '10 seconds' THEN | ||
-- Update the startedAt to current timestamp since it's older than 10 seconds and start this migration | ||
UPDATE "SchemaMigrationLock" SET "startedAt" = clock_timestamp() WHERE id = 1; | ||
END IF; |
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.
I think this will still potentially cause multiple migrations at the same time? the transactions are not cancelled if the lock is given to someone else after 10 seconds
This reverts commit af33ffa.
This reverts commit b41155d.
This reverts commit c0d4699.
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
- Update import path for migration files to point to the new generated location. - Rename function `isMigrationNeeded` to `isMigrationNeededError` for clarity. - Remove obsolete entry from .gitignore related to migration files. Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
- Introduced a call to the `seed()` function in the main migration process to ensure the database is populated with initial data after migration.
- Added a call to the `seed()` function back into the main migration flow to ensure the database is populated with initial data after executing migrations.
Important
Replaces Prisma's migration commands with custom scripts, updating workflows, scripts, and documentation to support new database migration strategy.
prisma migrate
commands with custom migration scripts indb-migrations.ts
.db:init
,db:reset
,db:seed
, anddb:migration-gen
commands inpackage.json
andapps/backend/package.json
.check-prisma-migrations.yaml
,e2e-api-tests.yaml
) to use new migration commands.db-migrations.ts
for handling database migrations, including reset, init, and seed operations.generate-migration-imports.ts
to generate migration imports.auto-migration.tests.ts
to test new migration logic.README.md
andself-host.mdx
to reflect new migration commands.turbo.json
to include new migration tasks.chokidar-cli
,dotenv
, andpostgres
toapps/backend/package.json
.This description was created by
for bfc09f3. You can customize this summary. It will automatically update as commits are pushed.