|
1 | 1 | import { ChildProcess, execFile, spawn } from "child_process" |
2 | | -import {coerce, satisfies} from 'semver'; |
| 2 | +import {coerce, gte, lt, satisfies} from 'semver'; |
3 | 3 | import * as os from 'os' |
4 | 4 | import * as fsPromises from 'fs/promises'; |
5 | 5 | import * as fs from 'fs'; |
@@ -71,7 +71,43 @@ class Executor { |
71 | 71 | const socket = os.platform() === 'win32' ? `MySQL-${randomUUID()}` : `${dbPath}/m.sock` |
72 | 72 | const xSocket = os.platform() === 'win32' ? `MySQLX-${randomUUID()}` : `${dbPath}/x.sock` |
73 | 73 |
|
74 | | - const process = spawn(binaryFilepath, ['--no-defaults', `--port=${port}`, `--datadir=${datadir}`, `--mysqlx-port=${mySQLXPort}`, `--mysqlx-socket=${xSocket}`, `--socket=${socket}`, `--general-log-file=${logFile}`, '--general-log=1', `--init-file=${dbPath}/init.sql`, '--bind-address=127.0.0.1', '--innodb-doublewrite=OFF', '--mysqlx=FORCE', `--log-error=${errorLogFile}`, `--user=${os.userInfo().username}`], {signal: this.DBDestroySignal.signal, killSignal: 'SIGKILL'}) |
| 74 | + const mysqlArguments = [ |
| 75 | + '--no-defaults', |
| 76 | + `--port=${port}`, |
| 77 | + `--datadir=${datadir}`, |
| 78 | + `--mysqlx-port=${mySQLXPort}`, |
| 79 | + `--mysqlx-socket=${xSocket}`, |
| 80 | + `--socket=${socket}`, |
| 81 | + `--general-log-file=${logFile}`, |
| 82 | + '--general-log=1', |
| 83 | + `--init-file=${dbPath}/init.sql`, |
| 84 | + '--bind-address=127.0.0.1', |
| 85 | + '--innodb-doublewrite=OFF', |
| 86 | + '--mysqlx=FORCE', |
| 87 | + `--log-error=${errorLogFile}`, |
| 88 | + `--user=${os.userInfo().username}` |
| 89 | + ] |
| 90 | + |
| 91 | + //<8.0.11 does not have MySQL X turned on by default so we will be installing the X Plugin in this if statement. |
| 92 | + //MySQL 5.7.12 introduced the X plugin, but according to https://dev.mysql.com/doc/refman/5.7/en/document-store-setting-up.html, the database needs to be initialised with version 5.7.19. |
| 93 | + //If the MySQL version is >=5.7.19 & <8.0.11 then install the X Plugin |
| 94 | + if (lt(this.version, '8.0.11') && gte(this.version, '5.7.19')) { |
| 95 | + const pluginExtension = os.platform() === 'win32' ? 'dll' : 'so'; |
| 96 | + let pluginPath: string; |
| 97 | + const firstPath = resolvePath(`${binaryFilepath}/../../lib/plugin`) |
| 98 | + const secondPath = '/usr/lib/mysql/plugin' |
| 99 | + |
| 100 | + if (fs.existsSync(`${firstPath}/mysqlx.${pluginExtension}`)) { |
| 101 | + pluginPath = firstPath |
| 102 | + } else if (os.platform() === 'linux' && fs.existsSync(`${secondPath}/mysqlx.so`)) { |
| 103 | + pluginPath = secondPath |
| 104 | + } else { |
| 105 | + throw 'Could not install MySQL X as the path to the plugin cannot be found.' |
| 106 | + } |
| 107 | + mysqlArguments.splice(1, 0, `--plugin-dir=${pluginPath}`, `--plugin-load-add=mysqlx=mysqlx.${pluginExtension}`) |
| 108 | + } |
| 109 | + |
| 110 | + const process = spawn(binaryFilepath, mysqlArguments, {signal: this.DBDestroySignal.signal, killSignal: 'SIGKILL'}) |
75 | 111 |
|
76 | 112 | //resolveFunction is the function that will be called to resolve the promise that stops the database. |
77 | 113 | //If resolveFunction is not undefined, the database has received a kill signal and data cleanup procedures should run. |
@@ -160,7 +196,7 @@ class Executor { |
160 | 196 | if (!killed) { |
161 | 197 | reject('Failed to kill MySQL process to retry listening on a free port.') |
162 | 198 | } |
163 | | - } else if (file.includes('ready for connections. Version:')) { |
| 199 | + } else if (file.includes('ready for connections. Version:') || file.includes('Server starts handling incoming connections')) { |
164 | 200 | fs.unwatchFile(errorLogFile) |
165 | 201 | resolve({ |
166 | 202 | port, |
|
0 commit comments