1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-17 05:58:01 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Karim Bouchez
98dbb9280f Merge 15337dfd71 into 6fb3b95ade 2024-05-16 05:28:57 +01:00
jbranchaud
6fb3b95ade Add Check If Database And Schema Are Not In Sync as a Prisma TIL 2024-05-15 12:21:38 -05:00
Karim Bouchez
15337dfd71 Update the old way to capture a GitHub Actions output
See [here](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) for more explanations:
> We are monitoring telemetry for the usage of these commands and plan to fully disable them on 31st May 2023. Starting 1st June 2023 workflows using save-state or set-output commands via stdout will fail with an error.
2023-02-12 10:36:45 +01:00
3 changed files with 42 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1429 TILs and counting..._
_1430 TILs and counting..._
---
@@ -824,6 +824,7 @@ _1429 TILs and counting..._
- [Apply Separate Formatting With A Blank Line](prisma/apply-separate-formatting-with-a-blank-line.md)
- [Batch Insert Records With createMany](prisma/batch-insert-records-with-create-many.md)
- [Check If Database And Schema Are Not In Sync](prisma/check-if-database-and-schema-are-not-in-sync.md)
- [Configure Client To Log SQL Queries](prisma/configure-client-to-log-sql-queries.md)
- [Execute A Raw SQL Query](prisma/execute-a-raw-sql-query.md)
- [Grab A Limited Set Of Records](prisma/grab-a-limited-set-of-records.md)

View File

@@ -23,11 +23,11 @@ version from my `.tool-versions` file with a step that uses `set-output`.
- name: Read Node.js version to install from `.tool-versions`
id: nodejs
run: >-
echo "::set-output name=NODE_VERSION::$(
echo "NODE_VERSION=$(
cat .tool-versions |
grep nodejs |
sed 's/nodejs \(.*\)$/\1/'
)"
)" >> $GITHUB_OUTPUT
```
`echo` runs the command in the string which sets `NODE_VERSION` as an output
@@ -45,4 +45,4 @@ This output value can be referenced in a later step.
`steps` has a reference to the `nodejs` step (note the `id` above) which then
has `outputs` like the `NODE_VERSION`.
[source](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions)
[source](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter)

View File

@@ -0,0 +1,37 @@
# Check If Database And Schema Are Not In Sync
The [`prisma migrate
diff`](https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff)
command is a versatile tool that can be used to check if there is a difference
between two sources. In this case, we want to check if our database is in sync
with the `schema.prisma` file for our project.
If we have made changes to the schema file, but haven't yet migrated or pushed
those changes to our local database, then we want to be notified of that
mismatch.
We'll point at the schema file with `--to-schema-datamodel` and at our local
database with `--from-url`.
```bash
npx prisma migrate diff \
--to-schema-datamodel ./prisma/schema.prisma \
--from-url mysql://root@localhost:3309/kcd-products
[*] Changed the `User` table
[+] Added column `metadata`
```
In the case where there is a different, we see an output summary of the diff.
Let's say we've applied our changes (`prisma db push`) to our local database.
If we now run that same command again, we can see that no difference is
detected and our database is in sync with our schema.
```bash
npx prisma migrate diff \
--to-schema-datamodel ./prisma/schema.prisma \
--from-url mysql://root@localhost:3309/kcd-products
No difference detected.
```