import type { Command } from '@prisma/sdk' ; import { arg , format , HelpError , isError , getSchemaPath , logger } from '@prisma/sdk' ; import chalk from 'chalk' ; import { getSeedCommandFromPackageJson , executeSeedCommand , verifySeedConfigAndReturnMessage , legacyTsNodeScriptWarning , } from '../utils/seed' ; export class DbSeed implements Command { public static new ( ) { return new DbSeed ( ) ; } private static help = format ( `
${ process . platform === 'win32' ? '' : chalk . bold ( '🙌  ' ) }Seed your database

${ chalk . bold ( 'Usage' ) }

  ${ chalk . dim ( '$' ) } prisma db seed [options]

${ chalk . bold ( 'Options' ) }

  -h, --help   Display this help message
` ) ; public async parse ( argv ) { const args = arg ( argv , { '--help' : Boolean , '-h' : '--help' , '--preview-feature' : Boolean , '--schema' : String , '--telemetry-information' : String , } , false ) ; if ( isError ( args ) ) { return this . help ( args . message ) ; } if ( args [ '--help' ] ) { return this . help ( ) ; } if ( args [ '--preview-feature' ] ) { logger . warn ( `Prisma "db seed" was in Preview and is now Generally Available.
You can now remove the ${ chalk . red ( '--preview-feature' ) } flag.` ) ; await legacyTsNodeScriptWarning ( ) ; } if ( args [ '--schema' ] ) { logger . warn ( chalk . yellow ( `The "--schema" parameter is not used anymore by "prisma db seed" since version 3.0 and can now be removed.` ) ) ; } const seedCommandFromPkgJson = await getSeedCommandFromPackageJson ( process . cwd ( ) ) ; if ( ! seedCommandFromPkgJson ) { const schemaPath = await getSchemaPath ( args [ '--schema' ] ) ; const message = await verifySeedConfigAndReturnMessage ( schemaPath ) ; if ( message ) { throw new Error ( message ) ; } return `` ; } const successfulSeeding = await executeSeedCommand ( seedCommandFromPkgJson ) ; if ( successfulSeeding ) { return `\n${ process . platform === 'win32' ? '' : '🌱  ' }The seed command has been executed.` ; } else { process . exit ( 1 ) ; return `` ; } } public help ( error ? ) { if ( error ) { return new HelpError ( `\n${ chalk . bold . red ( `!` ) } ${ error }\n${ DbSeed . help }` ) ; } return DbSeed . help ; } }