Skip to content

Commit

Permalink
fix(cli): dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed May 8, 2018
1 parent 8255714 commit 6a69a67
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cli/packages/prisma-cli-core/src/utils/EndpointDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface DatabaseCredentials {
password: string
database?: string
alreadyData?: boolean
schema?: string
}

export interface GetEndpointResult {
Expand Down Expand Up @@ -152,6 +153,10 @@ export class EndpointDialog {
credentials.database && credentials.database.length > 0
? credentials.database
: undefined,
schema:
credentials.schema && credentials.schema.length > 0
? credentials.schema
: undefined,
user: credentials.user,
password: credentials.password,
migrations: !credentials.alreadyData,
Expand Down Expand Up @@ -359,6 +364,11 @@ export class EndpointDialog {
// ['yes', 'no'].includes(value) ? true : 'Please answer either yes or no',
// })
const alreadyData = await this.askForExistingData()
if (type === 'mysql' && alreadyData) {
throw new Error(
`Existing MySQL databases with data are not yet supported.`,
)
}
const host = await this.ask({
message: 'Enter database host',
key: 'host',
Expand All @@ -380,12 +390,16 @@ export class EndpointDialog {
const database =
type === 'postgres'
? await this.ask({
message:
'Enter database name' +
(alreadyData ? ' (location of existing data)' : ''),
message: alreadyData
? `Enter name of existing database`
: `Enter database name`,
key: 'database',
})
: null
const schema = await this.ask({
message: `Enter name of existing schema`,
key: 'schema',
})

return {
type,
Expand All @@ -395,6 +409,7 @@ export class EndpointDialog {
password,
database,
alreadyData,
schema,
}
}

Expand Down

0 comments on commit 6a69a67

Please sign in to comment.