Skip to content

Commit 0b8a66b

Browse files
authored
feat: update more tests to use ppg dev (#8230)
* feat: update more tests to use ppg dev * fix: update schema.prisma file * fix: add schema path * fix: go back to root path * fix: update more readmes * fix: resolve prisma types in react router 7 code
1 parent fa1f829 commit 0b8a66b

File tree

25 files changed

+257
-217
lines changed

25 files changed

+257
-217
lines changed

.github/tests/orm/astro/run.sh

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,59 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -eu
44

5+
echo "🔍 Starting test setup..."
6+
7+
echo "📂 Current working directory before REPO_ROOT: $(pwd)"
8+
echo "📁 Listing contents:"
9+
ls -la
10+
11+
REPO_ROOT="$(git rev-parse --show-toplevel)"
12+
echo "📌 Detected repo root: $REPO_ROOT"
13+
14+
cd "$REPO_ROOT/orm/astro"
15+
echo "📂 Changed directory to: $(pwd)"
16+
17+
echo "📦 Installing test deps..."
18+
npm install
19+
20+
# Go to Node script dir and install its deps
21+
NODE_SCRIPT_DIR="../../.github/get-ppg-dev"
22+
pushd "$NODE_SCRIPT_DIR" > /dev/null
23+
npm install
24+
25+
# Start Prisma Dev server
26+
LOG_FILE="./ppg-dev-url.log"
27+
rm -f "$LOG_FILE"
28+
touch "$LOG_FILE"
29+
30+
echo "🚀 Starting Prisma Dev in background..."
31+
node index.js >"$LOG_FILE" &
32+
NODE_PID=$!
33+
34+
# Wait for DATABASE_URL
35+
echo "🔎 Waiting for Prisma Dev to emit DATABASE_URL..."
36+
MAX_WAIT=60
37+
WAITED=0
38+
until grep -q '^prisma+postgres://' "$LOG_FILE"; do
39+
sleep 1
40+
WAITED=$((WAITED + 1))
41+
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
42+
echo "❌ Timeout waiting for DATABASE_URL"
43+
cat "$LOG_FILE"
44+
kill "$NODE_PID" || true
45+
exit 1
46+
fi
47+
done
48+
49+
DB_URL=$(grep '^prisma+postgres://' "$LOG_FILE" | tail -1)
50+
export DATABASE_URL="$DB_URL"
51+
echo "✅ DATABASE_URL: $DATABASE_URL"
52+
53+
popd > /dev/null
54+
555
npm install
6-
npx prisma migrate dev --name init
56+
npx prisma migrate dev --name init --schema prisma/schema.prisma
757
npm run dev &
858
pid=$!
959

@@ -12,4 +62,8 @@ sleep 15
1262
# check frontend
1363
curl --fail 'http://localhost:4321/'
1464

65+
1566
kill "$pid"
67+
echo "🛑 App stopped (PID $pid)"
68+
kill "$NODE_PID"
69+
wait "$NODE_PID" || true

.github/tests/orm/betterauth-nextjs/run.sh

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,59 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -eu
44

5+
echo "🔍 Starting test setup..."
6+
7+
echo "📂 Current working directory before REPO_ROOT: $(pwd)"
8+
echo "📁 Listing contents:"
9+
ls -la
10+
11+
REPO_ROOT="$(git rev-parse --show-toplevel)"
12+
echo "📌 Detected repo root: $REPO_ROOT"
13+
14+
cd "$REPO_ROOT/orm/betterauth-nextjs"
15+
echo "📂 Changed directory to: $(pwd)"
16+
17+
echo "📦 Installing test deps..."
18+
npm install
19+
20+
# Go to Node script dir and install its deps
21+
NODE_SCRIPT_DIR="../../.github/get-ppg-dev"
22+
pushd "$NODE_SCRIPT_DIR" > /dev/null
23+
npm install
24+
25+
# Start Prisma Dev server
26+
LOG_FILE="./ppg-dev-url.log"
27+
rm -f "$LOG_FILE"
28+
touch "$LOG_FILE"
29+
30+
echo "🚀 Starting Prisma Dev in background..."
31+
node index.js >"$LOG_FILE" &
32+
NODE_PID=$!
33+
34+
# Wait for DATABASE_URL
35+
echo "🔎 Waiting for Prisma Dev to emit DATABASE_URL..."
36+
MAX_WAIT=60
37+
WAITED=0
38+
until grep -q '^prisma+postgres://' "$LOG_FILE"; do
39+
sleep 1
40+
WAITED=$((WAITED + 1))
41+
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
42+
echo "❌ Timeout waiting for DATABASE_URL"
43+
cat "$LOG_FILE"
44+
kill "$NODE_PID" || true
45+
exit 1
46+
fi
47+
done
48+
49+
DB_URL=$(grep '^prisma+postgres://' "$LOG_FILE" | tail -1)
50+
export DATABASE_URL="$DB_URL"
51+
echo "✅ DATABASE_URL: $DATABASE_URL"
52+
53+
popd > /dev/null
54+
555
npm install
6-
npx prisma migrate dev --name init
56+
npx prisma migrate dev --name init --schema prisma/schema.prisma
757
npx prisma db seed
858
npm run dev &
959
pid=$!
@@ -14,3 +64,6 @@ sleep 15
1464
curl --fail 'http://localhost:3000/'
1565

1666
kill "$pid"
67+
echo "🛑 App stopped (PID $pid)"
68+
kill "$NODE_PID"
69+
wait "$NODE_PID" || true

.github/tests/orm/clerk-nextjs/run.sh

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -eu
44

5+
echo "🔍 Starting test setup..."
6+
7+
echo "📂 Current working directory before REPO_ROOT: $(pwd)"
8+
echo "📁 Listing contents:"
9+
ls -la
10+
11+
REPO_ROOT="$(git rev-parse --show-toplevel)"
12+
echo "📌 Detected repo root: $REPO_ROOT"
13+
14+
cd "$REPO_ROOT/orm/clerk-nextjs"
15+
echo "📂 Changed directory to: $(pwd)"
16+
17+
echo "📦 Installing test deps..."
18+
npm install
19+
20+
# Go to Node script dir and install its deps
21+
NODE_SCRIPT_DIR="../../.github/get-ppg-dev"
22+
pushd "$NODE_SCRIPT_DIR" > /dev/null
23+
npm install
24+
25+
# Start Prisma Dev server
26+
LOG_FILE="./ppg-dev-url.log"
27+
rm -f "$LOG_FILE"
28+
touch "$LOG_FILE"
29+
30+
echo "🚀 Starting Prisma Dev in background..."
31+
node index.js >"$LOG_FILE" &
32+
NODE_PID=$!
33+
34+
# Wait for DATABASE_URL
35+
echo "🔎 Waiting for Prisma Dev to emit DATABASE_URL..."
36+
MAX_WAIT=60
37+
WAITED=0
38+
until grep -q '^prisma+postgres://' "$LOG_FILE"; do
39+
sleep 1
40+
WAITED=$((WAITED + 1))
41+
if [ "$WAITED" -ge "$MAX_WAIT" ]; then
42+
echo "❌ Timeout waiting for DATABASE_URL"
43+
cat "$LOG_FILE"
44+
kill "$NODE_PID" || true
45+
exit 1
46+
fi
47+
done
48+
49+
DB_URL=$(grep '^prisma+postgres://' "$LOG_FILE" | tail -1)
50+
export DATABASE_URL="$DB_URL"
51+
echo "✅ DATABASE_URL: $DATABASE_URL"
52+
53+
popd > /dev/null
54+
555
npm install
656
npx prisma migrate dev --name init
757
npm run dev &
@@ -13,3 +63,6 @@ sleep 15
1363
curl --fail 'http://localhost:3000/'
1464

1565
kill "$pid"
66+
echo "🛑 App stopped (PID $pid)"
67+
kill "$NODE_PID"
68+
wait "$NODE_PID" || true

.github/tests/orm/sveltekit/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ echo "✅ DATABASE_URL: $DATABASE_URL"
5353
popd > /dev/null # Back to orm/sveltekit
5454

5555
# Run migrations + seed
56-
npx prisma migrate dev --name init
56+
npx prisma migrate dev --name init --schema prisma/schema.prisma
5757
npx prisma db seed
5858

5959
# Start the app

orm/astro/README.md

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,29 @@ npm install
3535

3636
</details>
3737

38-
#### [Optional] Switch database to Prisma Postgres
38+
### 2. Add a Prisma Postgres instance connection string
3939

40-
This example uses a local SQLite database by default. If you want to use to [Prisma Postgres](https://prisma.io/postgres), follow these instructions (otherwise, skip to the next step):
40+
This example uses a [Prisma Postgres](https://prisma.io/postgres) database by default. To get started with the project, you will need to setup a Prisma Postgres connection string:
4141

42-
1. Set up a new Prisma Postgres instance in the Prisma Data Platform [Console](https://console.prisma.io) and copy the database connection URL.
43-
2. Update the `datasource` block to use `postgresql` as the `provider` and paste the database connection URL as the value for `url`:
42+
### 2. Create a Prisma Postgres instance
4443

45-
```prisma
46-
datasource db {
47-
provider = "postgresql"
48-
url = "prisma+postgres://accelerate.prisma-data.net/?api_key=ey...."
49-
}
50-
```
44+
This example uses a [Prisma Postgres](https://prisma.io/postgres) database by default. To get started with the project, you will need to setup a Prisma Postgres connection string:
5145

52-
> **Note**: In production environments, we recommend that you set your connection URL via an [environment variable](https://www.prisma.io/docs/orm/more/development-environment/environment-variables/managing-env-files-and-setting-variables), e.g. using a `.env` file.
46+
1. Set up a new Prisma Postgres instance in the [Prisma Data Platform Console](https://console.prisma.io) and copy the database connection URL.
5347

54-
3. Install the Prisma Accelerate extension:
55-
```
56-
npm install @prisma/extension-accelerate
57-
```
58-
4. Add the Accelerate extension to the `PrismaClient` instance:
59-
60-
```diff
61-
+ import { withAccelerate } from "@prisma/extension-accelerate"
62-
63-
+ const prisma = new PrismaClient().$extends(withAccelerate())
64-
```
65-
66-
5. Pass the `.env` var `DATABASE_URL` into the `PrismaClient()`
67-
```diff
68-
+ const prisma = new PrismaClient({
69-
+ datasourceUrl: import.meta.env.DATABASE_URL,
70-
+ }).$extends(withAccelerate())
71-
```
48+
2. Add your database url to the `.env`
7249

7350
That's it, your project is now configured to use Prisma Postgres!
7451

75-
### 2. Generate Prisma Client
52+
### 3. Generate Prisma Client
7653

7754
Run the following command to generate the Prisma Client. This is what you will be using to interact with your database.
7855

7956
```
8057
npx prisma generate
8158
```
8259

83-
### 3. Start the Astro server
60+
### 4. Start the Astro server
8461

8562
```
8663
npm run dev
@@ -90,7 +67,7 @@ The server is now running at http://localhost:4321
9067

9168
## Switch to another database
9269

93-
If you want to try this example with another database than SQLite, refer to the [Databases](https://www.prisma.io/docs/orm/overview/databases) section in our documentation
70+
If you want to try this example with another database rather than Prisma Postgres, refer to the [Databases](https://www.prisma.io/docs/orm/overview/databases) section in our documentation
9471

9572
## Next steps
9673

orm/astro/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@prisma/client": "6.9.0",
16+
"@prisma/extension-accelerate": "^2.0.1",
1617
"astro": "5.10.2"
1718
},
1819
"devDependencies": {

orm/astro/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ generator client {
1010
}
1111

1212
datasource db {
13-
provider = "sqlite"
14-
url = "file:./dev.db"
13+
provider = "postgresql"
14+
url = env("DATABASE_URL")
1515
}
1616

1717
model User {

orm/astro/prisma/seed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { withAccelerate } from '@prisma/extension-accelerate'
12
import { PrismaClient, Prisma } from '../src/generated/prisma'
23

3-
const prisma = new PrismaClient()
4+
const prisma = new PrismaClient().$extends(withAccelerate())
45

56
const userData: Prisma.UserCreateInput[] = [
67
{

orm/astro/src/lib/prisma.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { withAccelerate } from '@prisma/extension-accelerate'
12
import { PrismaClient } from '../generated/prisma'
23

3-
const prisma = new PrismaClient()
4+
const prisma = new PrismaClient().$extends(withAccelerate())
45

56
export default prisma

0 commit comments

Comments
 (0)