Skip to content

Commit

Permalink
chore(introspection): add introspected schema version to CLI output
Browse files Browse the repository at this point in the history
Closes #2424
  • Loading branch information
Jolg42 committed May 14, 2020
1 parent a08a958 commit b709695
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/packages/introspection/src/commands/Introspect.ts
Expand Up @@ -4,6 +4,7 @@ import path from 'path'
import {
IntrospectionEngine,
IntrospectionWarnings,
IntrospectionSchemaVersion,
uriToCredentials,
} from '@prisma/sdk'
import { formatms } from '../util/formatms'
Expand Down Expand Up @@ -108,10 +109,12 @@ export class Introspect implements Command {
const before = Date.now()
let introspectionSchema = ''
let introspectionWarnings: IntrospectionWarnings[]
let introspectionSchemaVersion: IntrospectionSchemaVersion
try {
const introspectionResult = await engine.introspect(schema)
introspectionSchema = introspectionResult.datamodel
introspectionWarnings = introspectionResult.warnings
introspectionSchemaVersion = introspectionResult.version
} catch (e) {
if (e.code === 'P4001') {
if (introspectionSchema.trim() === '') {
Expand Down Expand Up @@ -197,14 +200,20 @@ Then you can run ${chalk.green('prisma introspect')} again.

if (args['--print']) {
console.log(introspectionSchema)
introspectionSchemaVersion &&
console.log(
`\n// introspectionSchemaVersion: ${introspectionSchemaVersion}`,
)
console.error(introspectionWarningsMessage)
} else {
schemaPath = schemaPath || 'schema.prisma'
fs.writeFileSync(schemaPath, introspectionSchema)

log(`\n✔ Wrote Prisma data model into ${chalk.underline(
path.relative(process.cwd(), schemaPath),
)} in ${chalk.bold(formatms(Date.now() - before))}
)} in ${chalk.bold(formatms(Date.now() - before))} ${chalk.dim(
introspectionSchemaVersion || '',
)}
${chalk.keyword('orange')(introspectionWarningsMessage)}
Run ${chalk.green('prisma generate')} to generate Prisma Client.`)
}
Expand Down
12 changes: 11 additions & 1 deletion src/packages/sdk/src/IntrospectionEngine.ts
Expand Up @@ -71,6 +71,12 @@ interface IntrospectionWarningsInvalidEnumName {
affected: { enm: string; value: string }[]
}

export type IntrospectionSchemaVersion =
| 'Prisma2'
| 'Prisma1'
| 'Prisma11'
| 'NonPrisma'

let messageId = 1

/* tslint:disable */
Expand Down Expand Up @@ -122,7 +128,11 @@ export class IntrospectionEngine {
}
public introspect(
schema: string,
): Promise<{ datamodel: string; warnings: IntrospectionWarnings[] }> {
): Promise<{
datamodel: string
warnings: IntrospectionWarnings[]
version: IntrospectionSchemaVersion
}> {
this.lastUrl = schema
return this.runCommand(this.getRPCPayload('introspect', { schema }))
}
Expand Down
1 change: 1 addition & 0 deletions src/packages/sdk/src/index.ts
Expand Up @@ -11,6 +11,7 @@ export {
export {
IntrospectionEngine,
IntrospectionWarnings,
IntrospectionSchemaVersion,
} from './IntrospectionEngine'
export { Generator } from './Generator'
export { getGenerators, getGenerator, ProviderAliases } from './getGenerators'
Expand Down

0 comments on commit b709695

Please sign in to comment.