How to use the @prisma/cli.getSchemaDir 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
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
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

  if (code !== 'P1003') {
    throw new Error(`${code}: ${message}`)
  }

  // last case: status === 'DatabaseDoesNotExist'

  const schemaDir = await getSchemaDir()
  if (!schemaDir) {
    throw new Error(`Could not locate schema.prisma`)
  }
  if (forceCreate) {
    await createDatabase(activeDatasource.url.value, schemaDir)
  } else {
    await interactivelyCreateDatabase(activeDatasource.url.value, action, schemaDir)
  }
}
github prisma / lift / src / liftEngineCommands.ts View on Github external
async function doesSqliteDbExist(connectionString: string): Promise {
  let filePath = connectionString

  if (filePath.startsWith('file:')) {
    filePath = filePath.slice(5)
  }

  const cwd = await getSchemaDir()

  if (!cwd) {
    throw new Error(`Could not find schema.prisma in ${process.cwd()}`)
  }

  const absoluteTarget = path.resolve(cwd, filePath)

  return exists(absoluteTarget)
}

@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 3 years ago

Package Health Score

65 / 100
Full package analysis