discoverSchemaPath function

String discoverSchemaPath({
  1. String? explicitPath,
})

Discovers schema.prisma or validates an explicit schema path.

Implementation

String discoverSchemaPath({String? explicitPath}) {
  if (explicitPath != null) {
    final file = File(explicitPath).absolute;
    if (!file.existsSync()) {
      throw FormatException('Schema file not found: ${file.path}');
    }
    return file.path;
  }

  const candidates = <String>['prisma/schema.prisma', 'schema.prisma'];
  for (final candidate in candidates) {
    final file = File(candidate).absolute;
    if (file.existsSync()) {
      return file.path;
    }
  }

  throw const FormatException(
    'Could not find Prisma schema file.\n\n'
    'Checked the following paths:\n'
    '  - prisma/schema.prisma: file not found\n'
    '  - schema.prisma: file not found\n\n'
    'You can specify the schema path with --schema <path>.',
  );
}