Skip to content

Commit

Permalink
integrate new photon & lift
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Aug 15, 2019
1 parent b637efb commit 510dbc2
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 115 deletions.
20 changes: 4 additions & 16 deletions cli/cli/src/getCwd.ts
Expand Up @@ -5,7 +5,6 @@ import path from 'path'
const exists = promisify(fs.exists)
const readFile = promisify(fs.readFile)

const datamodelFile = 'project.prisma'
const schemaFile = 'schema.prisma'

/**
Expand All @@ -15,25 +14,17 @@ const schemaFile = 'schema.prisma'
*/
export async function getCwd(): Promise<string> {
const cwd = process.cwd()
const [
datamodelCwdExists,
schemaCwdExists,
prismaFolderExists,
prismaDatamodelExists,
prismaSchemaExists
] = await Promise.all([
exists(path.join(cwd, datamodelFile)),
const [schemaCwdExists, prismaFolderExists, prismaSchemaExists] = await Promise.all([
exists(path.join(cwd, schemaFile)),
exists(path.join(cwd, 'prisma/')),
exists(path.join(cwd, 'prisma/', datamodelFile)),
exists(path.join(cwd, 'prisma/', schemaFile)),
])

if (datamodelCwdExists || schemaCwdExists) {
if (schemaCwdExists) {
return cwd
}

if (prismaFolderExists || prismaDatamodelExists || prismaSchemaExists) {
if (prismaFolderExists || prismaSchemaExists) {
return path.join(cwd, 'prisma/')
}

Expand All @@ -42,10 +33,7 @@ export async function getCwd(): Promise<string> {

export async function getDatamodel(): Promise<string> {
const cwd = await getCwd()
let datamodelPath = path.join(cwd, datamodelFile)
if (!(await exists(datamodelPath))) {
datamodelPath = path.join(cwd, schemaFile)
}
const datamodelPath = path.join(cwd, schemaFile)
if (!(await exists(datamodelPath))) {
throw new Error(`Could not find ${datamodelPath}`)
}
Expand Down
5 changes: 3 additions & 2 deletions cli/introspection/package.json
@@ -1,12 +1,13 @@
{
"name": "@prisma/introspection",
"version": "0.0.39",
"version": "0.0.52",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"devDependencies": {
"@prisma/cli": "^0.0.42",
"@prisma/lift": "^0.1.21",
"@prisma/lift": "^0.2.0",
"@prisma/photon": "^0.2.0",
"@types/dotenv": "^6.1.1",
"@types/figures": "^3.0.1",
"@types/fs-extra": "^7.0.0",
Expand Down
8 changes: 1 addition & 7 deletions cli/introspection/src/commands/Init.ts
@@ -1,5 +1,4 @@
import { Command, Env, arg, format } from '@prisma/cli'
import { LiftEngine } from '@prisma/lift'
import { isError } from 'util'
import { promptInteractively } from '../prompt'
import { introspect } from '../introspect/util'
Expand All @@ -12,16 +11,11 @@ import { mkdirpSync } from 'fs-extra'
import { InitPromptResult } from '../types'

export class Init implements Command {
lift: LiftEngine
static new(env: Env): Init {
return new Init(env)
}

private constructor(private readonly env: Env) {
this.lift = new LiftEngine({
projectDir: env.cwd,
})
}
private constructor(private readonly env: Env) {}

async parse(argv: string[]): Promise<any> {
// parse the arguments according to the spec
Expand Down
5 changes: 1 addition & 4 deletions cli/introspection/src/commands/Introspect.ts
Expand Up @@ -139,10 +139,7 @@ ${chalk.bold('Created 1 new file:')} Prisma DML datamodel (derived from existing
}

getExistingDatamodel(): string | undefined {
let datamodelPath = path.join(this.env.cwd, 'project.prisma')
if (!fs.existsSync(datamodelPath)) {
datamodelPath = path.join(this.env.cwd, 'schema.prisma')
}
const datamodelPath = path.join(this.env.cwd, 'schema.prisma')
if (!fs.existsSync(datamodelPath)) {
return undefined
}
Expand Down
3 changes: 0 additions & 3 deletions cli/introspection/src/introspect/util.ts
Expand Up @@ -138,9 +138,6 @@ export async function getDatabaseSchemas(connector: IConnector): Promise<string[
}

function getSchemaPath(cwd: string): string | undefined {
if (existsSync(join(cwd, 'project.prisma'))) {
return join(cwd, 'project.prisma')
}
if (existsSync(join(cwd, 'schema.prisma'))) {
return join(cwd, 'schema.prisma')
}
Expand Down
24 changes: 24 additions & 0 deletions cli/introspection/src/test-introspection.ts
@@ -0,0 +1,24 @@
import { getConnectedConnectorFromCredentials } from './introspect/util'
import { DatabaseType } from 'prisma-datamodel'
import { isdlToDatamodel2 } from '@prisma/photon'

async function main() {
const { connector, disconnect } = await getConnectedConnectorFromCredentials({
type: DatabaseType.postgres,
uri:
'postgresql://prisma:qd58rcCywPRS4Stk@introspection-database-postgres.cluster-clfeqqifnebj.eu-west-1.rds.amazonaws.com:5432/random-database1',
})

const schemas = await connector.listSchemas()
console.log(schemas)
const result = await connector.introspect('public')
console.log(result)
const isdl = result.getDatamodel()
console.log(isdl)
const dmmf = await isdlToDatamodel2(isdl, [])
console.log(dmmf)

disconnect()
}

main()

0 comments on commit 510dbc2

Please sign in to comment.