Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main(): Promise {
// create a new CLI with our subcommands
const cli = LiftCommand.new({
save: LiftSave.new(),
up: LiftUp.new(),
down: LiftDown.new(),
dev: LiftWatch.new(providerAliases),
['tmp-prepare']: LiftTmpPrepare.new(),
studio: StudioCommand.new(providerAliases),
})
// parse the arguments
const result = await cli.parse(process.argv.slice(2))
if (result instanceof HelpError) {
console.error(result)
return 1
} else if (isError(result)) {
console.error(result)
return 1
}
console.log(result)
return 0
}
process.on('SIGINT', () => {
'tmp-prepare': LiftTmpPrepare.new(),
introspect: Introspect.new(),
dev: LiftWatch.new(aliases),
studio: StudioCommand.new(aliases),
generate: Generate.new(),
version: Version.new(),
validate: Validate.new(),
},
['init', 'lift', 'tmp-prepare', 'introspect', 'dev', 'studio', 'generate', 'validate'],
)
// parse the arguments
const result = await cli.parse(process.argv.slice(2))
if (result instanceof HelpError) {
console.error(result.message)
return 1
} else if (isError(result)) {
console.error(result)
return 1
}
console.log(result)
return 0
}
async function main(): Promise {
process.env.NODE_ENV = 'production'
// create a new CLI with our subcommands
const args = arg(process.argv.slice(2), {})
if (isError(args)) {
console.error(args.message)
return 1
}
const commands = {
init: Init.new(),
introspect: Introspect.new(),
}
if (commands[args._[0]]) {
const result = await commands[args._[0]].parse(process.argv.slice(3))
console.log(result)
} else {
console.error(`Command not found: ${args._[0]}. Available commands: ${Object.keys(commands).join(', ')}`)
return 1
}
async function main(): Promise {
process.env.NODE_ENV = 'production'
// create a new CLI with our subcommands
const args = arg(process.argv.slice(2), {})
if (isError(args)) {
console.error(args.message)
return 1
}
const commands = {
init: Init.new(),
introspect: Introspect.new(),
}
if (commands[args._[0]]) {
const result = await commands[args._[0]].parse(process.argv.slice(3))
console.log(result)
} else {
console.error(`Command not found: ${args._[0]}. Available commands: ${Object.keys(commands).join(', ')}`)
if (migration.warnings && migration.warnings.length > 0) {
console.log(chalk.bold(`\n\n⚠️ There might be data loss when applying the migration:\n`))
for (const warning of migration.warnings) {
console.log(chalk(` • ${warning.description}`))
}
console.log()
}
if (preview) {
lift.stop()
return `\nRun ${chalk.greenBright('prisma lift save --name MIGRATION_NAME')} to create the migration\n`
}
await getSchema() // just to leverage on its error handling
const schemaDir = (await getSchemaDir())! // TODO: Probably getSchemaDir() should return Promise instead of Promise
const migrationsDir = path.join(schemaDir, 'migrations', migrationId)
await serializeFileMap(files, migrationsDir)
const lockFilePath = path.join(schemaDir, 'migrations', 'lift.lock')
await writeFile(lockFilePath, newLockFile)
lift.stop()
return `\nLift just created your migration ${printMigrationId(migrationId)} in\n\n${chalk.dim(
printFiles(`migrations/${migrationId}`, files),
)}\n\nRun ${chalk.greenBright('prisma2 lift up')} to apply the migration\n`
}
public async parse(argv: string[], minimalOutput = false): Promise {
const datamodelPath = await getSchemaPath()
if (!datamodelPath) {
throw new Error(`Can't find schema.prisma`) // TODO: Add this into a central place in getSchemaPath() as an arg
}
const generators = await getGenerators({
schemaPath: datamodelPath,
providerAliases: this.aliases,
printDownloadProgress: true,
version: pkg.prisma.version,
})
if (generators.length === 0) {
console.log(missingGeneratorMessage)
}
// CONTINUE HERE
export async function getCredentialsFromExistingDatamodel(): Promise {
const schemaPath = await getSchemaPath()
if (schemaPath) {
const datamodel = readFileSync(schemaPath, 'utf-8')
const { datasources } = await getConfig({ datamodel })
// For now just take the first data source
if (datasources && datasources.length > 1) {
console.error(
`There are more than 1 datasources listed in the datamodel ${datasources.map(d => d.name).join(', ')}, taking ${
datasources[0].name
}`,
)
}
if (datasources && datasources.length > 0) {
const uri = datasources[0].url.value
return uriToCredentials(uri)
}
}
const { files, newLockFile, migrationId } = await lift.save(migration, name, preview)
if (migration.warnings && migration.warnings.length > 0) {
console.log(chalk.bold(`\n\n⚠️ There might be data loss when applying the migration:\n`))
for (const warning of migration.warnings) {
console.log(chalk(` • ${warning.description}`))
}
console.log()
}
if (preview) {
lift.stop()
return `\nRun ${chalk.greenBright('prisma lift save --name MIGRATION_NAME')} to create the migration\n`
}
await getSchema() // just to leverage on its error handling
const schemaDir = (await getSchemaDir())! // TODO: Probably getSchemaDir() should return Promise instead of Promise
const migrationsDir = path.join(schemaDir, 'migrations', migrationId)
await serializeFileMap(files, migrationsDir)
const lockFilePath = path.join(schemaDir, 'migrations', 'lift.lock')
await writeFile(lockFilePath, newLockFile)
lift.stop()
return `\nLift just created your migration ${printMigrationId(migrationId)} in\n\n${chalk.dim(
printFiles(`migrations/${migrationId}`, files),
)}\n\nRun ${chalk.greenBright('prisma2 lift up')} to apply the migration\n`
}
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
})
if (isError(args)) {
return this.help(args.message)
}
// display help for help flag or no subcommand
if (args._.length === 0 || args['--help']) {
return this.help()
}
// check if we have that subcommand
const cmd = this.cmds[args._[0]]
if (cmd) {
const nextFreePort = await getNextFreePort(process.cwd())
if (typeof nextFreePort !== 'number') {
const command = `prisma2 lift ${argv.join(' ')}`
throw new Error(`Cannot run ${chalk.bold(command)} because there is a ${chalk.bold(
'prisma2 dev',
)} command running in this directory.
Please ${gamboge(`stop ${chalk.bold('prisma2 dev')} first`)}, then try ${chalk.greenBright.bold(command)} again`)
public async parse(argv: string[]): Promise {
// parse the arguments according to the spec
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
})
if (isError(args)) {
return this.help(args.message)
} else if (args['--help']) {
return this.help()
}
const datamodel = await this.readStdin()
const engine = new LiftEngine({ projectDir: process.cwd() })
const parser = DefaultParser.create(DatabaseType.postgres)
const isdl = parser.parseFromSchemaString(datamodel)
return isdlToDatamodel2(isdl, [])
}