Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(client): add vitess flavor in relationMode test suite #16051

Merged
merged 15 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions .buildkite/publish/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
# Functional test URLS
- TEST_FUNCTIONAL_POSTGRES_URI=postgres://prisma:prisma@postgres:5432/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MYSQL_URI=mysql://root:root@mysql:3306/PRISMA_DB_NAME
- TEST_FUNCTIONAL_VITESS_8_URI=mysql://root:root@localhost:33807/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MSSQL_URI=sqlserver://mssql:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
- TEST_FUNCTIONAL_MONGO_URI=mongodb://root:prisma@mongo:27018/PRISMA_DB_NAME?authSource=admin
- TEST_FUNCTIONAL_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/PRISMA_DB_NAME
Expand Down Expand Up @@ -74,6 +75,7 @@ services:
- mongodb_migrate
- mongodb_migrate_seed
- cockroachdb
- vitess-8
Jolg42 marked this conversation as resolved.
Show resolved Hide resolved

postgres:
image: postgres:10
Expand Down Expand Up @@ -125,6 +127,20 @@ services:
ports:
- '3307:3306'

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
jkomyno marked this conversation as resolved.
Show resolved Hide resolved
restart: always
ports:
- 33807:33807
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'keyspace' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver

MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'

mariadb:
image: mariadb:10.7.3
restart: always
Expand Down
16 changes: 16 additions & 0 deletions .buildkite/test/docker-compose.14.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
# Functional test URLS
- TEST_FUNCTIONAL_POSTGRES_URI=postgres://prisma:prisma@postgres:5432/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MYSQL_URI=mysql://root:root@mysql:3306/PRISMA_DB_NAME
- TEST_FUNCTIONAL_VITESS_8_URI=mysql://root:root@localhost:33807/PRISMA_DB_NAME
- TEST_FUNCTIONAL_MSSQL_URI=sqlserver://mssql:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;
- TEST_FUNCTIONAL_MONGO_URI=mongodb://root:prisma@mongo:27018/PRISMA_DB_NAME?authSource=admin
- TEST_FUNCTIONAL_COCKROACH_URI=postgresql://prisma@cockroachdb:26257/PRISMA_DB_NAME
Expand All @@ -64,6 +65,7 @@ services:
- mongodb_migrate
- mongodb_migrate_seed
- cockroachdb
- vitess-8
Jolg42 marked this conversation as resolved.
Show resolved Hide resolved

postgres:
image: postgres:10
Expand Down Expand Up @@ -115,6 +117,20 @@ services:
ports:
- '3307:3306'

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
restart: always
ports:
- 33807:33807
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'keyspace' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver

MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'

mariadb:
image: mariadb:10.7.3
restart: always
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
TEST_COCKROACH_SHADOWDB_URI_MIGRATE: 'postgres://prisma:prisma@localhost:26257/tests-migrate-shadowdb'
TEST_FUNCTIONAL_POSTGRES_URI: 'postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MYSQL_URI: 'mysql://root:root@localhost:3306/PRISMA_DB_NAME'
TEST_FUNCTIONAL_VITESS_8_URI: 'mysql://root:root@localhost:33807/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MSSQL_URI: 'sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;'
TEST_FUNCTIONAL_MONGO_URI: 'mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin'
TEST_FUNCTIONAL_COCKROACH_URI: 'postgresql://prisma@localhost:26257/PRISMA_DB_NAME'
Expand All @@ -160,7 +161,7 @@ jobs:
echo "RELATION_MODE=${{ matrix.relationMode }}"
if [ ! -z "${{ matrix.relationMode }}" ]; then echo "RELATION_MODE=${{ matrix.relationMode }}" >> $GITHUB_ENV; fi

- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb
- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb vitess-8

- uses: pnpm/action-setup@v2.2.4
with:
Expand Down Expand Up @@ -227,6 +228,7 @@ jobs:
TEST_COCKROACH_SHADOWDB_URI_MIGRATE: 'postgres://prisma:prisma@localhost:26257/tests-migrate-shadowdb'
TEST_FUNCTIONAL_POSTGRES_URI: 'postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MYSQL_URI: 'mysql://root:root@localhost:3306/PRISMA_DB_NAME'
TEST_FUNCTIONAL_VITESS_8_URI: 'mysql://root:root@localhost:33807/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MSSQL_URI: 'sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;'
TEST_FUNCTIONAL_MONGO_URI: 'mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin'
TEST_FUNCTIONAL_COCKROACH_URI: 'postgresql://prisma@localhost:26257/PRISMA_DB_NAME'
Expand All @@ -253,7 +255,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 mongo cockroachdb
- run: docker-compose -f docker/docker-compose.yml up --detach postgres postgres_isolated mysql mysql_isolated mssql mongo cockroachdb vitess-8
jkomyno marked this conversation as resolved.
Show resolved Hide resolved

- uses: pnpm/action-setup@v2.2.4
with:
Expand Down Expand Up @@ -310,7 +312,7 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb
- run: docker-compose -f docker/docker-compose.yml up --detach postgres mysql mssql mongo cockroachdb vitess-8
jkomyno marked this conversation as resolved.
Show resolved Hide resolved

- uses: pnpm/action-setup@v2.2.4
with:
Expand All @@ -335,6 +337,7 @@ jobs:
GITHUB_CONTEXT: ${{ toJson(github) }}
TEST_FUNCTIONAL_POSTGRES_URI: 'postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MYSQL_URI: 'mysql://root:root@localhost:3306/PRISMA_DB_NAME'
TEST_FUNCTIONAL_VITESS_8_URI: 'mysql://root:root@localhost:33807/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MSSQL_URI: 'sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;'
TEST_FUNCTIONAL_MONGO_URI: 'mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin'
TEST_FUNCTIONAL_COCKROACH_URI: 'postgresql://prisma@localhost:26257/PRISMA_DB_NAME'
Expand All @@ -348,6 +351,7 @@ jobs:
GITHUB_CONTEXT: ${{ toJson(github) }}
TEST_FUNCTIONAL_POSTGRES_URI: 'postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MYSQL_URI: 'mysql://root:root@localhost:3306/PRISMA_DB_NAME'
TEST_FUNCTIONAL_VITESS_8_URI: 'mysql://root:root@localhost:33807/PRISMA_DB_NAME'
TEST_FUNCTIONAL_MSSQL_URI: 'sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;'
TEST_FUNCTIONAL_MONGO_URI: 'mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin'
TEST_FUNCTIONAL_COCKROACH_URI: 'postgresql://prisma@localhost:26257/PRISMA_DB_NAME'
Expand Down
1 change: 1 addition & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ To run tests requiring a database, start the test databases using Docker, see [D
# Prisma Client - Functional test suite
export TEST_FUNCTIONAL_POSTGRES_URI="postgres://prisma:prisma@localhost:5432/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_MYSQL_URI="mysql://root:root@localhost:3306/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_VITESS_8_URI="mysql://root:root@localhost:33807/PRISMA_DB_NAME"
export TEST_FUNCTIONAL_MSSQL_URI="sqlserver://localhost:1433;database=PRISMA_DB_NAME;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;"
export TEST_FUNCTIONAL_MONGO_URI="mongodb://root:prisma@localhost:27018/PRISMA_DB_NAME?authSource=admin"
export TEST_FUNCTIONAL_COCKROACH_URI="postgresql://prisma@localhost:26257/PRISMA_DB_NAME"
Expand Down
46 changes: 22 additions & 24 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ services:
# Planetscale
# From https://github.com/prisma/prisma-engines/blob/976a00ae3c30ab9507fa742986c9c6f5327ba10f/docker-compose.yml

vitess-8:
image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
restart: always
ports:
- 33807:33807
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-h127.0.0.1', '-P33577']
interval: 5s
timeout: 2s
retries: 5
start_period: 25s
environment:
PORT: '33804' # unused in testing, but required by vttestserver
KEYSPACES: 'unsharded' # unused in testing, but required by vttestserver
NUM_SHARDS: '1' # unused in testing, but required by vttestserver
MYSQL_BIND_HOST: '0.0.0.0'
FOREIGN_KEY_MODE: 'disallow'
VT_DIALECT: 'mysql80'
PLANNER_VERSION: 'gen4fallback'
TOPOLOGY_FLAGS: '-shutdown_grace_period 2'
jkomyno marked this conversation as resolved.
Show resolved Hide resolved

# vitess-test-5_7:
# image: vitess/vttestserver:mysql57@sha256:2b132a22d08b3b227d9391f8f58ed7ab5c081ca07bf0f87a0c166729124d360a
# restart: always
Expand All @@ -44,19 +65,7 @@ services:
# NUM_SHARDS: "1"
# MYSQL_BIND_HOST: "0.0.0.0"
# FOREIGN_KEY_MODE: "disallow"

# vitess-test-8_0:
# image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
# restart: always
# ports:
# - 33807:33807
# environment:
# PORT: 33804
# KEYSPACES: 'test'
# NUM_SHARDS: '1'
# MYSQL_BIND_HOST: '0.0.0.0'
# FOREIGN_KEY_MODE: 'disallow'

#
# vitess-shadow-5_7:
# image: vitess/vttestserver:mysql57@sha256:2b132a22d08b3b227d9391f8f58ed7ab5c081ca07bf0f87a0c166729124d360a
# restart: always
Expand All @@ -69,17 +78,6 @@ services:
# MYSQL_BIND_HOST: "0.0.0.0"
# FOREIGN_KEY_MODE: "disallow"
#
# vitess-shadow-8_0:
# image: vitess/vttestserver:mysql80@sha256:9412e3d51bde38e09c3039090b5c68808e299579f12c79178a4ec316f7831889
# restart: always
# ports:
# - 33808:33807
# environment:
# PORT: 33804
# KEYSPACES: 'shadow'
# NUM_SHARDS: '1'
# MYSQL_BIND_HOST: '0.0.0.0'
# FOREIGN_KEY_MODE: 'disallow'

mysql:
image: mysql:8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ function getTestSuiteParametersString(configs: Record<string, string>[]) {
// For `relationMode` tests
// we hardcode how it lookks like for test results
if (config.relationMode !== undefined) {
return `relationMode=${config.relationMode},provider=${config.provider},onUpdate=${config.onUpdate},onDelete=${config.onDelete},id=${config.id}`
const providerFlavorStr = config.providerFlavor === undefined ? '' : `providerFlavor=${config.providerFlavor},`
return `relationMode=${config.relationMode},provider=${config.provider},${providerFlavorStr}onUpdate=${config.onUpdate},onDelete=${config.onDelete},id=${config.id}`
} else {
const firstKey = Object.keys(config)[0]
return `${firstKey}=${config[firstKey]}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Providers } from '../providers'

export enum ProviderFlavors {
VITESS_8 = 'vitess_8',
}

const providerFlavors = [...Object.values(Providers), ProviderFlavors.VITESS_8] as const
export type ProviderFlavor = typeof providerFlavors[number]

export function getProviderFromFlavor(providerFlavor: ProviderFlavor): Providers {
switch (providerFlavor) {
case ProviderFlavors.VITESS_8:
return Providers.MYSQL
default:
return providerFlavor
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Providers } from '../providers'
import { getProviderFromFlavor, ProviderFlavor, ProviderFlavors } from './ProviderFlavor'

type ComputeMatrix = {
relationMode: 'prisma' | 'foreignKeys' | ''
providersDenyList?: Providers[]
providersDenyList?: ProviderFlavor[]
}

export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix) {
const providersBase = [
const providerFlavorsBase = [
Providers.POSTGRESQL,
Providers.COCKROACHDB,
Providers.SQLSERVER,
Providers.MYSQL,
Providers.SQLITE,
Providers.MYSQL,
ProviderFlavors.VITESS_8,
] as const
// Note: SetDefault is not implemented in the emulation (relationMode="prisma")

Expand All @@ -22,7 +24,9 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix

const referentialActionsBase = ['DEFAULT', 'Cascade', 'NoAction', 'Restrict', 'SetNull'] as const

const providers = providersBase.filter((provider) => !(providersDenyList || []).includes(provider))
const providerFlavors = providerFlavorsBase.filter(
(provideFlavor) => !(providersDenyList || []).includes(provideFlavor),
)

// "foreignKeys"
//
Expand All @@ -42,9 +46,12 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
//
// We skip these combinations in the matrix (= filtering them out)

const referentialActionsDenylistByProvider = {
const referentialActionsDenylistByProviderFlavor = {
foreignKeys: {
[Providers.SQLSERVER]: ['Restrict'],

// skip all actions for Vitess & relationMode="foreignKeys" as Foreign Keys are not supported by that provider
[ProviderFlavors.VITESS_8]: referentialActionsBase,
},
prisma: {
[Providers.SQLSERVER]: ['Restrict'],
Expand All @@ -53,14 +60,16 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
},
}

const providersMatrix = providers.map((provider) => ({
provider,
const providersMatrix = providerFlavors.map((providerFlavor) => ({
provider: getProviderFromFlavor(providerFlavor),
providerFlavor,
id: 'String @id',
relationMode,
}))

const referentialActionsMatrix = providersMatrix.flatMap((entry) => {
const denyList = referentialActionsDenylistByProvider[relationMode || 'foreignKeys'][entry.provider] || []
const denyList =
referentialActionsDenylistByProviderFlavor[relationMode || 'foreignKeys'][entry.providerFlavor] || []
const referentialActions = referentialActionsBase.filter((action) => !denyList.includes(action))

const referentialActionMatrixForSQL = referentialActions.map((referentialAction) => ({
Expand All @@ -78,6 +87,7 @@ export function computeMatrix({ relationMode, providersDenyList }: ComputeMatrix
if (!relationMode || relationMode === 'prisma') {
const mongoDBMatrixBase = {
provider: Providers.MONGODB,
providerFlavor: getProviderFromFlavor(Providers.MONGODB),
id: 'String @id @map("_id")',
relationMode: 'prisma',
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { match } from 'ts-pattern'

import { Providers } from '../providers'
import type { ProviderFlavor } from './ProviderFlavor'

export type ComputeSchemaHeader = {
provider: Providers
providerFlavor: ProviderFlavor
previewFeatures: string
relationMode: string
}

export function computeSchemaHeader({ provider, previewFeatures, relationMode }: ComputeSchemaHeader): string {
const USE_PLANETSCALE = false

export function computeSchemaHeader({
provider,
providerFlavor,
previewFeatures,
relationMode,
}: ComputeSchemaHeader): string {
// if relationModeLine is not defined, we do not add the line
// if relationModeLine is defined
// we add the line only if the provider is not MongoDB, since MongoDB doesn't need the setting, it's on by default
const relationModeLine = provider === Providers.MONGODB || !relationMode ? '' : `relationMode = "${relationMode}"`

const url = match(provider)
.when(
(_provider) => USE_PLANETSCALE && _provider === Providers.MYSQL,
(_provider) => `"mysql://root:root@127.0.0.1:33807/PRISMA_DB_NAME"`,
)
.with(Providers.SQLITE, (_provider) => `"file:test.db"`)
.otherwise((_provider) => `env("DATABASE_URI_${provider}")`)
const url = match({ provider, providerFlavor })
.with({ provider: Providers.SQLITE }, () => `"file:test.db"`)
.otherwise(({ providerFlavor }) => `env("DATABASE_URI_${providerFlavor}")`)

const schemaHeader = /* Prisma */ `
generator client {
Expand Down