| 52 | export type SchemaEngineCLIOptions = SchemaEngineCLISetupInput |
| 53 | |
| 54 | export class SchemaEngineCLI implements SchemaEngine { |
| 55 | private debug: boolean |
| 56 | private child?: ChildProcess |
| 57 | private schemaContext?: SchemaContext |
| 58 | private datasource?: Datasource |
| 59 | private listeners: { [key: string]: (result: any, err?: any) => any } = {} |
| 60 | /** _All_ the logs from the engine process. */ |
| 61 | private messages: string[] = [] |
| 62 | private lastRequest?: any |
| 63 | /** The fields of the last engine log event with an `ERROR` level. */ |
| 64 | private lastError: SchemaEngineLogLine['fields'] | null = null |
| 65 | private initPromise?: Promise<void> |
| 66 | private enabledPreviewFeatures?: string[] |
| 67 | private extensionConfig?: SchemaExtensionConfig |
| 68 | private baseDir: string |
| 69 | |
| 70 | // `isRunning` is set to true when the engine is initialized, and set to false when the engine is stopped |
| 71 | public isRunning = false |
| 72 | |
| 73 | private constructor({ |
| 74 | debug = false, |
| 75 | schemaContext, |
| 76 | datasource, |
| 77 | enabledPreviewFeatures, |
| 78 | extensions, |
| 79 | baseDir, |
| 80 | }: SchemaEngineCLIOptions) { |
| 81 | this.schemaContext = schemaContext |
| 82 | this.datasource = datasource |
| 83 | if (debug) { |
| 84 | Debug.enable('SchemaEngine*') |
| 85 | } |
| 86 | this.debug = debug |
| 87 | this.enabledPreviewFeatures = enabledPreviewFeatures |
| 88 | this.extensionConfig = extensions ? { types: extensions.flatMap((ext) => ext.types) } : undefined |
| 89 | this.baseDir = baseDir |
| 90 | } |
| 91 | |
| 92 | static setup(input: SchemaEngineCLISetupInput): Promise<SchemaEngineCLI> { |
| 93 | return Promise.resolve(new SchemaEngineCLI(input)) |
| 94 | } |
| 95 | |
| 96 | // |
| 97 | // See JSON-RPC API definition: |
| 98 | // https://prisma.github.io/prisma-engines/doc/migration_core/json_rpc/index.html |
| 99 | // |
| 100 | |
| 101 | /** |
| 102 | * Apply the migrations from the migrations directory to the database. |
| 103 | * This is the command behind prisma migrate deploy. |
| 104 | */ |
| 105 | public applyMigrations(args: EngineArgs.ApplyMigrationsInput): Promise<EngineResults.ApplyMigrationsOutput> { |
| 106 | return this.runCommand(this.getRPCPayload('applyMigrations', args)) |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Create the logical database from the Prisma schema. |
| 111 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected