Skip to content

Commit

Permalink
test(client): Add cockroachdb blog tests (#10772)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrensmith committed Dec 21, 2021
1 parent 1f8e4ef commit f0631b2
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .buildkite/publish/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
- TEST_MSSQL_SHADOWDB_JDBC_URI_MIGRATE=sqlserver://mssql:1433;database=tests-migrate-shadowdb;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
# MongoDB
- TEST_MONGO_URI=mongodb://root:prisma@mongo:27017/tests?authSource=admin
# CockroachDB
- TEST_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/
# Other vars !\ If not defined, they cannot be accessed
# TODO: do an env var cleanup?
- NPM_TOKEN
Expand Down Expand Up @@ -58,6 +60,7 @@ services:
- mssql
- mongo
- mongo-seed
- cockroachdb

postgres:
image: postgres:10
Expand Down Expand Up @@ -138,12 +141,18 @@ services:
links:
- mongo

cockroachdb:
image: prismagraphql/build:cockroach-custom
restart: always
command: start-single-node --insecure
ports:
- '26257:26257'

volumes:
postgres:
postgres_isolated:
mysql:
mysql_isolated:
mariadb:
mssql:

# TODO: investigate why isolated containers aren't used in the tests
10 changes: 10 additions & 0 deletions .buildkite/test/docker-compose.14.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
- TEST_MSSQL_SHADOWDB_JDBC_URI_MIGRATE=sqlserver://mssql:1433;database=tests-migrate-shadowdb;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
# MongoDB
- TEST_MONGO_URI=mongodb://root:prisma@mongo:27017/tests?authSource=admin
# CockroachDB
- TEST_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/
# Other vars
- BUILDKITE
- BUILDKITE_PARALLEL_JOB
Expand All @@ -48,6 +50,7 @@ services:
- mssql
- mongo
- mongo-seed
- cockroachdb

postgres:
image: postgres:10
Expand Down Expand Up @@ -128,6 +131,13 @@ services:
links:
- mongo

cockroachdb:
image: prismagraphql/build:cockroach-custom
restart: always
command: start-single-node --insecure
ports:
- '26257:26257'

volumes:
postgres:
postgres_isolated:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
run: |
echo "PRISMA_CLIENT_ENGINE_TYPE=${{ matrix.queryEngine }}" >> $GITHUB_ENV
- run: docker-compose -f docker/docker-compose.yml up --detach postgres postgres_isolated mysql mysql_isolated mssql
- run: docker-compose -f docker/docker-compose.yml up --detach postgres postgres_isolated mysql mysql_isolated mssql cockroachdb

- name: Cache .pnpm-store # From https://pnpm.io/continuous-integration
uses: actions/cache@v1
Expand Down
2 changes: 2 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export TEST_MSSQL_JDBC_URI_MIGRATE="sqlserver://localhost:1433;database=tests-mi
export TEST_MSSQL_SHADOWDB_JDBC_URI_MIGRATE="sqlserver://localhost:1433;database=tests-migrate-shadowdb;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;"

export TEST_MONGO_URI="mongodb://root:prisma@localhost:27017/tests?authSource=admin"

export TEST_COCKROACH_URI=postgresql://prisma@localhost:26257/
```

- Load the environnment variables with:
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
# Outside Docker
# - TEST_POSTGRES_URI_MIGRATE=postgres://prisma:prisma@localhost:5432/tests-migrate
# - TEST_POSTGRES_URI=postgres://prisma:prisma@localhost:5432/tests
# - TEST_COCKROACH_URI=postgresql://prisma@localhost:26257/
# - TEST_POSTGRES_ISOLATED_URI=postgres://prisma:prisma@localhost:5435/tests
# - TEST_MYSQL_URI=mysql://prisma:prisma@localhost:3306/tests
# - TEST_MYSQL_ISOLATED_URI=mysql://prisma:prisma@localhost:3307/tests
Expand Down Expand Up @@ -46,6 +47,13 @@ services:
ports:
- '5435:5432'

cockroachdb:
image: prismagraphql/build:cockroach-custom
restart: always
command: start-single-node --insecure
ports:
- '26257:26257'

mysql:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Blog fixture: Cockroachdb $queryRaw $queryRaw(string) error 1`] = `
\`$queryRaw\` is a tag function, please use it like the following:
\`\`\`
const result = await prisma.$queryRaw\`SELECT * FROM User WHERE id = \${1} OR email = \${'user@email.com'};\`
\`\`\`
Or read our docs at https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#queryraw
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
datasource db {
provider = "cockroachdb"
url = env("TEST_COCKROACH_URI")
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["cockroachdb"]
}

// / User model comment
model User {
id String @id @default(uuid())
email String @unique
// / name comment
name String?
posts Post[]
}

model Post {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
jsonData Json?
coinflips Boolean[]
authorId String?
author User? @relation(fields: [authorId], references: [id])
}

enum Role {
USER
ADMIN
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
DROP TYPE IF EXISTS "Role";
CREATE TYPE "Role" AS ENUM ('USER', 'ADMIN');
DROP TABLE IF EXISTS "public"."Post" CASCADE;
CREATE TABLE "public"."Post" (
"id" text NOT NULL,
"createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" timestamp(3) NOT NULL DEFAULT '1970-01-01 00:00:00'::timestamp without time zone,
"published" boolean NOT NULL DEFAULT false,
"title" text NOT NULL,
"content" text,
"authorId" text,
"jsonData" jsonb,
"coinflips" _bool,
PRIMARY KEY ("id")
);
DROP TABLE IF EXISTS "public"."User" CASCADE;
CREATE TABLE "public"."User" (
"id" text,
"email" text NOT NULL,
"name" text,
PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "User.email" ON "public"."User"("email");
ALTER TABLE "public"."Post"
ADD FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE
SET NULL ON UPDATE CASCADE;
INSERT INTO "public"."User" (email, id, name)
VALUES (
'a@a.de',
'576eddf9-2434-421f-9a86-58bede16fd95',
'Alice'
);
Loading

0 comments on commit f0631b2

Please sign in to comment.