1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-18 22:48:02 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Karim Bouchez
2808b39828 Merge 15337dfd71 into 84e2c9c6f4 2024-05-21 10:06:13 +05:30
jbranchaud
84e2c9c6f4 Add Override Table Name For Prisma Model as a Prisma TIL 2024-05-20 09:05:44 -05:00
jbranchaud
39614e975e Add Find Top-Level Directories Matching A Pattern as a Unix TIL 2024-05-19 10:08:45 -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
4 changed files with 84 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).
_1431 TILs and counting..._
_1433 TILs and counting..._
---
@@ -830,6 +830,7 @@ _1431 TILs and counting..._
- [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)
- [Open Connections To Multiple Databases](prisma/open-connections-to-multiple-databases.md)
- [Override Table Name For Prisma Model](prisma/override-table-name-for-prisma-model.md)
- [Specify Alternate Location For Prisma Schema](prisma/specify-alternate-location-for-prisma-schema.md)
### Python
@@ -1377,6 +1378,7 @@ _1431 TILs and counting..._
- [Find Files With fd](unix/find-files-with-fd.md)
- [Find Newer Files](unix/find-newer-files.md)
- [Find Occurrences Of Multiple Values With Ripgrep](unix/find-occurrences-of-multiple-values-with-ripgrep.md)
- [Find Top-Level Directories Matching A Pattern](unix/find-top-level-directories-matching-a-pattern.md)
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)
- [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.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,42 @@
# Override Table Name For Prisma Model
When defining your Prisma schema, you'll add models to your
`prisma/schema.prisma` file that look something like this:
```
model Book {
id BigInt @id @default(autoincrement()) @db.BigInt
title String
author String
publication_year Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt
}
```
The prisma client (ORM-layer) that gets generated will have a `Book` type and
you'll be able to reference the model to, for instance, create a record with
`prisma.book.create(...)`. Both of these things are derived from the model
name: `Book`.
The other thing that is derived from the model name is the name given to the
underlying database table. So you end up with a table called `Book`. You may,
however, prefer a table naming convention where this one would be named `books`
(snake_case and pluralized).
To achieve that, you have to manually override the table name with [the `@@map`
directive](https://www.prisma.io/docs/orm/reference/prisma-schema-reference#map-1).
Add it toward the bottom of the model like so:
```
model Book {
id BigInt @id @default(autoincrement()) @db.BigInt
title String
author String
publication_year Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt
@@map("books")
}
```

View File

@@ -0,0 +1,36 @@
# Find Top-Level Directories Matching A Pattern
I like using [`fd`](https://github.com/sharkdp/fd) as an alternative to `find`.
In my experience it is more intuitive to use. For instance, I wanted to find
all the top-level directories in my current directory that contained the word
`next`. I was able to get the command mostly right by guessing the flags, only
checking the man page once.
On my first attempt, it prompted me with a suggestion for a flag that wasn't
quite right. I tried `--depth`, but it should have been `--maxdepth`.
```bash
$ fd --depth 0 next ./
error: Found argument '--depth' which wasn't expected, or isn't valid in this context
Did you mean --maxdepth?
```
Then I checked the man page for how to specify the file type as _directory_ --
using `-t` or `--type` with `d`.
And here is the command that gets me all top-level directories matching `next`
in my current directory:
```bash
$ fd --maxdepth 1 --type d next ./
bookshelf-nextjs-prisma-postgres
bookshelf-prisma-nextjs-planetscale
my-next-app
next-bookshelf
next-personal-site
next-sanity-v3-example
try-trpc-next
```
See `man fd` for more details.