Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/schema/src/plugins/prisma/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
const MODEL_PASSTHROUGH_ATTR = '@@prisma.passthrough';
const FIELD_PASSTHROUGH_ATTR = '@prisma.passthrough';
const PROVIDERS_SUPPORTING_NAMED_CONSTRAINTS = ['postgresql', 'mysql', 'cockroachdb'];
const PROVIDERS_SUPPORTING_TYPEDEF_FIELDS = ['postgresql'];
const PROVIDERS_SUPPORTING_TYPEDEF_FIELDS = ['postgresql', 'sqlite'];

// Some database providers like postgres and mysql have default limit to the length of identifiers
// Here we use a conservative value that should work for most cases, and truncate names if needed
Expand Down
34 changes: 19 additions & 15 deletions tests/integration/tests/enhancements/json/crud.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { createPostgresDb, dropPostgresDb, loadSchema } from '@zenstackhq/testtools';

describe('Json field CRUD', () => {
describe.each(['sqlite' as const, 'postgresql' as const])('Json field CRUD - %p', (provider) => {
let dbUrl: string;
let prisma: any;

beforeEach(async () => {
dbUrl = await createPostgresDb('json-field-typing');
if (provider === 'postgresql') {
dbUrl = await createPostgresDb('json-field-typing');
}
});

afterEach(async () => {
if (prisma) {
await prisma.$disconnect();
if (provider === 'postgresql') {
if (prisma) {
await prisma.$disconnect();
}
await dropPostgresDb(dbUrl);
}
await dropPostgresDb(dbUrl);
});

it('works with simple cases', async () => {
Expand Down Expand Up @@ -41,7 +45,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
enhancements: ['validation'],
}
Expand Down Expand Up @@ -90,7 +94,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -137,7 +141,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -211,7 +215,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -255,7 +259,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -291,7 +295,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -328,7 +332,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -368,7 +372,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -401,7 +405,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
}
);
Expand Down Expand Up @@ -446,7 +450,7 @@ describe('Json field CRUD', () => {
}
`,
{
provider: 'postgresql',
provider,
dbUrl,
compile: true,
extraSourceFiles: [
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/tests/enhancements/json/typing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loadSchema } from '@zenstackhq/testtools';

describe('JSON field typing', () => {
describe.each(['sqlite' as const, 'postgresql' as const])('JSON field typing - %p', (provider) => {
it('works with simple field', async () => {
await loadSchema(
`
Expand All @@ -23,7 +23,7 @@ describe('JSON field typing', () => {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -64,7 +64,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -105,7 +105,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -151,7 +151,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -203,7 +203,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -252,7 +252,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -303,7 +303,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down Expand Up @@ -348,7 +348,7 @@ async function main() {
}
`,
{
provider: 'postgresql',
provider,
pushDb: false,
compile: true,
extraSourceFiles: [
Expand Down
18 changes: 0 additions & 18 deletions tests/integration/tests/enhancements/json/validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { loadModel, loadModelWithError, loadSchema } from '@zenstackhq/testtools';

describe('JSON field typing', () => {
it('is only supported by postgres', async () => {
await expect(
loadSchema(
`
type Profile {
age Int @gt(0)
}

model User {
id Int @id @default(autoincrement())
profile Profile @json
@@allow('all', true)
}
`
)
).rejects.toThrow('Datasource provider "sqlite" does not support "@json" fields');
});

it('requires field to have @json attribute', async () => {
await expect(
loadModelWithError(
Expand Down
Loading