Skip to content

Commit

Permalink
chore(planetscale): reuse the same planetscale database for all ecosy…
Browse files Browse the repository at this point in the history
…stem tests (#5804)
  • Loading branch information
FGoessler authored Feb 7, 2025
1 parent ffdcc38 commit 46c6aea
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 27 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ jobs:
DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_DATABASE_URL }}
DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_PROJECT_ID: ${{ vars.DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_PROJECT_ID }}
# planetscale
DRIVER_ADAPTERS_PLANETSCALE_LAMBDA_BASIC_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_PLANETSCALE_LAMBDA_BASIC_DATABASE_URL }}
DRIVER_ADAPTERS_PLANETSCALE_NODE_BASIC_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_PLANETSCALE_NODE_BASIC_DATABASE_URL }}
DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_DATABASE_URL }}
DATABASE_URL_PLANETSCALE: ${{ secrets.DATABASE_URL_PLANETSCALE }}
DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_PROJECT_ID: ${{ vars.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_PROJECT_ID }}
# libsql (Turso)
DRIVER_ADAPTERS_TURSO_LAMBDA_BASIC_DATABASE_URL: ${{ vars.DRIVER_ADAPTERS_TURSO_LAMBDA_BASIC_DATABASE_URL }}
Expand Down Expand Up @@ -410,9 +408,8 @@ jobs:
DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_APP_EDGEFN_PROJECT_ID: ${{ vars.DRIVER_ADAPTERS_NEON_VERCEL_NEXTJS_APP_EDGEFN_PROJECT_ID }}
DRIVER_ADAPTERS_NEON_NODE_NEXTJS_EDGEMW_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_NEON_NODE_NEXTJS_EDGEMW_DATABASE_URL }}
# planetscale
DRIVER_ADAPTERS_PLANETSCALE_CF_BASIC_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_PLANETSCALE_CF_BASIC_DATABASE_URL }}
# DRIVER_ADAPTERS_PLANETSCALE_CFPAGES_BASIC_DATABASE_URL: only configured via UI, as cloudflare pages can not upload env var values per deployment
DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_DATABASE_URL: ${{ secrets.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_DATABASE_URL }}
DATABASE_URL_PLANETSCALE: ${{ secrets.DATABASE_URL_PLANETSCALE }}
# For cloudflare pages only configured via UI, as cloudflare pages can not upload env var values per deployment
DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_PROJECT_ID: ${{ vars.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_PROJECT_ID }}
# Turso
DRIVER_ADAPTERS_TURSO_CF_BASIC_DATABASE_URL: ${{ vars.DRIVER_ADAPTERS_TURSO_CF_BASIC_DATABASE_URL }}
Expand Down
5 changes: 5 additions & 0 deletions databases/planetscale/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ PlanetScale Database
### Environment Variables

Set the env var `DATABASE_URL_PLANETSCALE`

> [!NOTE]
> Note that all planetscale tests share the same database but operate on different tables.
> They use the database "e2e-tests" in the prisma org.
> The `[email protected]` has full access to this. => See 1Password.
2 changes: 1 addition & 1 deletion driver-adapters-wasm/planetscale-cf-basic/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export PRISMA_TELEMETRY_INFORMATION='ecosystem-tests driver-adapters-wasm planet
export PRISMA_CLIENT_ENGINE_TYPE='wasm' # because setup otherwise makes it library/binary

cp -fr wrangler.base.toml wrangler.toml # needed for retries
echo "DRIVER_ADAPTERS_PLANETSCALE_CF_BASIC_DATABASE_URL=\"$DRIVER_ADAPTERS_PLANETSCALE_CF_BASIC_DATABASE_URL\"" >> wrangler.toml
echo "DATABASE_URL_PLANETSCALE=\"$DATABASE_URL_PLANETSCALE\"" >> wrangler.toml

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ model User {
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_cf_basic")
}
2 changes: 1 addition & 1 deletion driver-adapters-wasm/planetscale-cf-basic/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
export default {
async fetch(request, env, ctx) {
const client = new Client({
url: env.DRIVER_ADAPTERS_PLANETSCALE_CF_BASIC_DATABASE_URL,
url: env.DATABASE_URL_PLANETSCALE,
// taken from cloudflare's docs https://developers.cloudflare.com/workers/databases/native-integrations/planetscale/#:~:text=fetch%3A%20(,init)%3B
fetch(url, init) {
delete init['cache']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PrismaPlanetScale } from '@prisma/adapter-planetscale'

export async function onRequest(context) {
const client = new Client({
url: context.env.DRIVER_ADAPTERS_PLANETSCALE_CFPAGES_BASIC_DATABASE_URL,
url: context.env.DATABASE_URL_PLANETSCALE,
// taken from cloudflare's docs https://developers.cloudflare.com/workers/databases/native-integrations/planetscale/#:~:text=fetch%3A%20(,init)%3B
fetch(url, init) {
delete init['cache']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ model User {
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_cfpages_basic")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PrismaPlanetScale } from '@prisma/adapter-planetscale'

async function getResponse() {
const client = new Client({
url: process.env.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_DATABASE_URL,
url: process.env.DATABASE_URL_PLANETSCALE,
// taken from cloudflare's docs https://developers.cloudflare.com/workers/databases/native-integrations/planetscale/#:~:text=fetch%3A%20(,init)%3B
fetch(url, init) {
delete init['cache']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ datasource db {
}

model User {
id String @default(cuid()) @id
id String @id @default(cuid())
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_vercel_nextjs_edgemw")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pnpm vercel deploy \
--token=$VERCEL_TOKEN \
--build-env DEBUG="prisma:*" \
--env DEBUG="prisma:*" \
--env DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_DATABASE_URL=$DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_EDGEMW_DATABASE_URL \
--env DATABASE_URL_PLANETSCALE=$DATABASE_URL_PLANETSCALE \
--scope=$VERCEL_ORG_ID 1> deployment-url.txt

echo ''
Expand Down
2 changes: 1 addition & 1 deletion driver-adapters/planetscale-lambda-basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Prisma, PrismaClient } = require('@prisma/client')
const { Client } = require('@planetscale/database')
const { PrismaPlanetScale } = require('@prisma/adapter-planetscale')

const connectionString = process.env.DRIVER_ADAPTERS_PLANETSCALE_LAMBDA_BASIC_DATABASE_URL
const connectionString = process.env.DATABASE_URL_PLANETSCALE

const client = new Client({ url: connectionString })
const adapter = new PrismaPlanetScale(client)
Expand Down
8 changes: 5 additions & 3 deletions driver-adapters/planetscale-lambda-basic/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
previewFeatures = ["driverAdapters"]
}

Expand All @@ -11,8 +11,10 @@ datasource db {
}

model User {
id String @default(cuid()) @id
id String @id @default(cuid())
email String @unique
name String?
age Int?
@@map("user_lambda_basic")
}
2 changes: 1 addition & 1 deletion driver-adapters/planetscale-lambda-basic/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ cp "$GENERATED_CLIENT"/libquery_engine-rhel-openssl-1.0.x.so.node dist
cp "$GENERATED_CLIENT"/schema.prisma dist
zip -rj lambda.zip dist

aws lambda update-function-configuration --function-name driver-adapters-planetscale-lambda-basic --runtime nodejs18.x --environment "Variables={DRIVER_ADAPTERS_PLANETSCALE_LAMBDA_BASIC_DATABASE_URL=$DRIVER_ADAPTERS_PLANETSCALE_LAMBDA_BASIC_DATABASE_URL}" --timeout 30
aws lambda update-function-configuration --function-name driver-adapters-planetscale-lambda-basic --runtime nodejs18.x --environment "Variables={DATABASE_URL_PLANETSCALE=$DATABASE_URL_PLANETSCALE}" --timeout 30
aws lambda update-function-code --function-name driver-adapters-planetscale-lambda-basic --zip-file "fileb://lambda.zip"
Empty file modified driver-adapters/planetscale-lambda-basic/test.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion driver-adapters/planetscale-node-basic-esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrismaClient } from '@prisma/client'
import { Client } from '@planetscale/database'
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'

const connectionString = process.env.DRIVER_ADAPTERS_PLANETSCALE_NODE_BASIC_DATABASE_URL
const connectionString = process.env.DATABASE_URL_PLANETSCALE

const client = new Client({ url: connectionString })
const adapter = new PrismaPlanetScale(client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

Expand All @@ -10,8 +10,13 @@ datasource db {
}

model User {
id String @default(cuid()) @id
id String @id @default(cuid())
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_node_basic_esm")
}
2 changes: 1 addition & 1 deletion driver-adapters/planetscale-node-basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Prisma, PrismaClient } = require('@prisma/client')
const { Client } = require('@planetscale/database')
const { PrismaPlanetScale } = require('@prisma/adapter-planetscale')

const connectionString = process.env.DRIVER_ADAPTERS_PLANETSCALE_NODE_BASIC_DATABASE_URL
const connectionString = process.env.DATABASE_URL_PLANETSCALE

const client = new Client({ url: connectionString })
const adapter = new PrismaPlanetScale(client)
Expand Down
9 changes: 7 additions & 2 deletions driver-adapters/planetscale-node-basic/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

Expand All @@ -10,8 +10,13 @@ datasource db {
}

model User {
id String @default(cuid()) @id
id String @id @default(cuid())
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_node_basic")
}
Empty file modified driver-adapters/planetscale-node-basic/test.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Prisma, PrismaClient } = require('@prisma/client')
const { Client } = require('@planetscale/database')
const { PrismaPlanetScale } = require('@prisma/adapter-planetscale')

const connectionString = process.env.DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_DATABASE_URL
const connectionString = process.env.DATABASE_URL_PLANETSCALE

const client = new Client({ url: connectionString })
const adapter = new PrismaPlanetScale(client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

Expand All @@ -10,8 +10,13 @@ datasource db {
}

model User {
id String @default(cuid()) @id
id String @id @default(cuid())
email String @unique
name String?
age Int?
// Note that all planetscale tests share the same database but operate on different tables.
// They use the database "e2e-tests" in the prisma org.
// The `[email protected]` has full access to this. => See 1Password.
@@map("user_vercel_nextjs")
}
2 changes: 1 addition & 1 deletion driver-adapters/planetscale-vercel-nextjs/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pnpm vercel deploy \
--token=$VERCEL_TOKEN \
--build-env DEBUG="prisma:*" \
--build-env PRISMA_CLIENT_ENGINE_TYPE="$PRISMA_CLIENT_ENGINE_TYPE" \
--env DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_DATABASE_URL=$DRIVER_ADAPTERS_PLANETSCALE_VERCEL_NEXTJS_DATABASE_URL \
--env DATABASE_URL_PLANETSCALE=$DATABASE_URL_PLANETSCALE \
--scope=$VERCEL_ORG_ID 1> deployment-url.txt

echo ''
Expand Down
Empty file modified driver-adapters/planetscale-vercel-nextjs/test.sh
100644 → 100755
Empty file.

0 comments on commit 46c6aea

Please sign in to comment.