Skip to content

Commit

Permalink
Add db.prismaPath configuration (#8307)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 19, 2023
1 parent 4887a7c commit d33bb47
Show file tree
Hide file tree
Showing 120 changed files with 444 additions and 243 deletions.
5 changes: 5 additions & 0 deletions .changeset/depend-on-me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes assumptions about `@prisma/client` output location, with a new `db.prismaPath` configuration option to set where to import the Prisma client from
4 changes: 4 additions & 0 deletions examples/assets-local/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
storage: {
Expand Down
2 changes: 1 addition & 1 deletion examples/assets-local/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
4 changes: 4 additions & 0 deletions examples/assets-s3/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from '@keystone-6/core';
import dotenv from 'dotenv';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

dotenv.config();
Expand All @@ -15,6 +16,9 @@ export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
storage: {
Expand Down
2 changes: 1 addition & 1 deletion examples/assets-s3/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
4 changes: 4 additions & 0 deletions examples/auth/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config } from '@keystone-6/core';
import { statelessSessions } from '@keystone-6/core/session';
import { createAuth } from '@keystone-6/auth';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

// WARNING: this example is for demonstration purposes only
Expand Down Expand Up @@ -59,6 +60,9 @@ export default withAuth(
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
session,
Expand Down
2 changes: 1 addition & 1 deletion examples/auth/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model User {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-admin-ui-logo/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
ui: {},
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-logo/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-admin-ui-navigation/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-navigation/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-admin-ui-pages/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/custom-admin-ui-pages/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-field-view/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/custom-field-view/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-field/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/custom-field/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-session-validation/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { KeystoneConfig, SessionStrategy } from '@keystone-6/core/types';
import { config } from '@keystone-6/core';
import { statelessSessions } from '@keystone-6/core/session';
import { createAuth } from '@keystone-6/auth';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

// createAuth configures signin functionality based on the config below. Note this only implements
Expand Down Expand Up @@ -91,6 +92,9 @@ export default myAuth(
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
// We add our session configuration to the system here.
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-session-validation/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
4 changes: 4 additions & 0 deletions examples/default-values/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/default-values/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from '@keystone-6/core';
import type { KeystoneConfig } from '@keystone-6/core/types';
import { fixPrismaPath } from '../../example-utils';
import { seedDatabase } from './src/seed';
import { lists } from './src/schema';
import { Context, TypeInfo } from '.keystone/types';
Expand All @@ -12,6 +13,9 @@ const db: KeystoneConfig<TypeInfo>['db'] = {
await seedDatabase(context);
}
},

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
};

export default config({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model User {
Expand Down
4 changes: 4 additions & 0 deletions examples/document-field/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
});
2 changes: 1 addition & 1 deletion examples/document-field/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
10 changes: 10 additions & 0 deletions examples/example-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// our monorepo examples have their @prisma/client dependencies hoisted
// to build them and use them without conflict, we need to ensure .prisma/client
// resolves to somewhere else
//
// we use node_modules/.myprisma to differentiate from node_modules/.prisma, but
// still use node_modules/... to skip the painful experience that is jest/babel
// transforms
export const fixPrismaPath = {
prismaPath: 'node_modules/.myprisma/client',
};
4 changes: 4 additions & 0 deletions examples/extend-express-app/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists } from './schema';
import { getTasks } from './routes/tasks';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
server: {
/*
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-express-app/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Task {
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-express-app/seed-data.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getContext } from '@keystone-6/core/context';
import { persons, tasks } from '../example-data';
import config from './keystone';
import * as PrismaModule from '.prisma/client';
import * as PrismaModule from '.myprisma/client';

type PersonProps = {
name: string;
Expand Down
4 changes: 4 additions & 0 deletions examples/extend-graphql-schema-graphql-tools/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists, extendGraphqlSchema } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
extendGraphqlSchema,
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-graphql-schema-graphql-tools/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
4 changes: 4 additions & 0 deletions examples/extend-graphql-schema-graphql-ts/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { config } from '@keystone-6/core';
import { fixPrismaPath } from '../example-utils';
import { lists, extendGraphqlSchema } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
...fixPrismaPath,
},
lists,
extendGraphqlSchema,
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-graphql-schema-graphql-ts/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource sqlite {

generator client {
provider = "prisma-client-js"
output = "node_modules/.prisma/client"
output = "node_modules/.myprisma/client"
}

model Post {
Expand Down
Loading

0 comments on commit d33bb47

Please sign in to comment.