Skip to content
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

test(ci): Test Prisma migrations #160

Merged
merged 3 commits into from
Dec 6, 2024
Merged

test(ci): Test Prisma migrations #160

merged 3 commits into from
Dec 6, 2024

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Dec 6, 2024

What does this PR do?

  • Changes the name of a column to test migrations on CI
  • This needed to be done using the --create-only flag - without this Prisma would drop and recreate the column. I needed to manually write the correct SQL in the migration file.
  • Adds basic doc to explain process

image

Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fairhold-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 6, 2024 2:18pm

"prisma:migrate": "dotenv -e .env.local npx prisma migrate dev",
"prisma:studio": "dotenv -e .env.local npx prisma studio",
"prisma:migrate": "dotenv -e .env.local -- npx prisma migrate dev",
"prisma:migrate-create-only": "dotenv -e .env.local -- npx prisma migrate dev --create-only",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent way too long trying to get the --create-only flag to be picked up here.

Classic case of RTFM 🤦 - explainer in docs here why the additional -- is required https://www.prisma.io/docs/orm/more/development-environment/environment-variables/managing-env-files-and-setting-variables#using-dotenv-cli-via-command-line

@DafyddLlyr DafyddLlyr marked this pull request as draft December 6, 2024 12:10
@DafyddLlyr DafyddLlyr changed the title ci: Test Prisma migrations test(ci): Test Prisma migrations Dec 6, 2024
@DafyddLlyr DafyddLlyr requested a review from a team December 6, 2024 14:05
@DafyddLlyr DafyddLlyr marked this pull request as ready for review December 6, 2024 14:06
Run `npm run prisma:migrate` - this will apply to the change to your local dev database, and generate a migration file in `/prisma/migrations`

> [!TIP]
> The command `npm run prisma:migrate-create-only` will generate a migration file without running it. This is helpful if you want to add any additional changes, and manually configure the migration. For example when renaming a column Prisma may drop and recreate (thus losing data). Manually generating an `ALTER table UPDATE column` SQL command allows us to work around this. You'll then need to run `npm run prisma:migrate` to apply your changes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm being silly but I don't quite understand where "Manually generating an ALTER table UPDATE column SQL command" should be happening

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated the docs now. Is this any clearer?

Keen to jump on a call and demo this so we're all confident making changes 🙂

Copy link
Collaborator

@zz-hh-aa zz-hh-aa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one small q, super clear though!

Copy link
Collaborator

@zz-hh-aa zz-hh-aa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Thanks :)

@DafyddLlyr DafyddLlyr merged commit 4cb34ff into main Dec 6, 2024
5 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/test-ci-migrations branch December 6, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants