How to use the @prisma/cli.getSchema function in @prisma/cli

To help you get started, weโ€™ve selected a few @prisma/cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prisma / lift / src / cli / commands / LiftSave.ts View on Github external
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`
  }
github prisma / lift / src / utils / ensureDatabaseExists.tsx View on Github external
export async function ensureDatabaseExists(action: LiftAction, killInk: boolean, forceCreate: boolean = false) {
  const datamodel = await getSchema()
  const config = await getConfig({ datamodel })
  const activeDatasource =
    config.datasources.length === 1
      ? config.datasources[0]
      : config.datasources.find(d => d.config.enabled === 'true') || config.datasources[0]

  if (!activeDatasource) {
    throw new Error(`Couldn't find a datasource in the schema.prisma file`)
  }

  const canConnect = await canConnectToDatabase(activeDatasource.url.value)
  if (canConnect === true) {
    return
  }
  const { code, message } = canConnect

@prisma/cli

Prisma is an open-source database toolkit. It includes a JavaScript/TypeScript ORM for Node.js, migrations and a modern GUI to view and edit the data in your database. You can use Prisma in new projects or add it to an existing one.

Apache-2.0
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis