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

Fix misleading error when db.url is undefined #8696

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/better-errors-please.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fixes misleading error when `db.url` is `undefined`
1 change: 1 addition & 0 deletions packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export async function generateTypescriptTypesAndPrisma(
if (dataProxy === true) {
console.log('✨ Generating Prisma Client (data proxy)');
}

await Promise.all([
generatePrismaClient(paths.schema.prisma, dataProxy),
generateTypescriptTypes(cwd, config, graphQLSchema),
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ function applyIdFieldDefaults(config: KeystoneConfig): KeystoneConfig['lists'] {

export function initConfig(config: KeystoneConfig) {
if (!['postgresql', 'sqlite', 'mysql'].includes(config.db.provider)) {
throw new Error(
throw new TypeError(
'Invalid db configuration. Please specify db.provider as either "sqlite", "postgresql" or "mysql"'
);
}

// WARNING: Typescript should prevent this, but empty string is useful for Prisma errors
config.db.url ??= 'postgres://';

// TODO: use zod or something if want to follow this path
return {
...config,
lists: applyIdFieldDefaults(config),
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ type PrismaLogDefinition = {
};

export type DatabaseConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
provider: DatabaseProvider;
url: string;

shadowDatabaseUrl?: string;
onConnect?: (args: KeystoneContext<TypeInfo>) => Promise<void>;
/** @deprecated */
useMigrations?: boolean;
enableLogging?: boolean | PrismaLogLevel | Array<PrismaLogLevel | PrismaLogDefinition>;
idField?: IdFieldConfig;
provider: DatabaseProvider;
prismaClientPath?: string;
extendPrismaSchema?: (schema: string) => string;

/** @deprecated */
useMigrations?: boolean;
/** @deprecated use extendPrismaSchema */
prismaPreviewFeatures?: readonly string[]; // https://www.prisma.io/docs/concepts/components/preview-features
/** @deprecated use extendPrismaSchema */
additionalPrismaDatasourceProperties?: { [key: string]: string };

prismaClientPath?: string;
extendPrismaSchema?: (schema: string) => string;
};

// config.ui
Expand Down