Skip to content

Commit 6137d84

Browse files
Merge pull request #155 from Sebastian-Webster/154-expose-mysql-server-version-via-createdb-resolved-object
Expose MySQL version
2 parents 0368f65 + 4798888 commit 6137d84

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function main() {
3939
}
4040
console.log('Creating ephemeral MySQL database...')
4141
const db = await createDB(options);
42-
console.log(`A MySQL database has been successfully created with the following parameters:\n\nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`)
42+
console.log(`A MySQL database has been successfully created with the following parameters:\n\nMySQL Version: ${db.version} \nUsername: ${db.username} \nDatabase Name: ${db.dbName} \nPort: ${db.port} \nX Plugin Port: ${db.xPort} \nSocket: ${db.socket} \nX Plugin Socket: ${db.xSocket}\n`)
4343
if (process.platform === 'win32') {
4444
//The connection information logs will be different for Windows compared to other platforms.
4545
//Windows uses mysqlsh instead of mysql to invoke the client shell, needs a --sql flag to be put into SQL mode, and also does not have a protocol flag.

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export async function createDB(opts?: ServerOptions) {
7878
}
7979

8080
logger.log('Running downloaded binary')
81-
return await executor.startMySQL(options, binaryFilepath)
81+
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version})
8282
} else {
8383
logger.log(version)
84-
return await executor.startMySQL(options, version.path)
84+
return await executor.startMySQL(options, version)
8585
}
8686
}

src/libraries/Executor.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { randomUUID } from "crypto";
1414
class Executor {
1515
logger: Logger;
1616
DBDestroySignal = new AbortController();
17-
removeExitHandler: () => void
17+
removeExitHandler: () => void;
18+
version: string;
1819

1920
constructor(logger: Logger) {
2021
this.logger = logger;
@@ -190,6 +191,7 @@ class Executor {
190191
xSocket,
191192
dbName: options.dbName,
192193
username: options.username,
194+
version: this.version,
193195
stop: () => {
194196
return new Promise(async (resolve, reject) => {
195197
resolveFunction = resolve;
@@ -420,7 +422,8 @@ class Executor {
420422
this.logger.log('Finished writing init file')
421423
}
422424

423-
async startMySQL(options: InternalServerOptions, binaryFilepath: string): Promise<MySQLDB> {
425+
async startMySQL(options: InternalServerOptions, installedMySQLBinary: InstalledMySQLVersion): Promise<MySQLDB> {
426+
this.version = installedMySQLBinary.version
424427
this.removeExitHandler = onExit(() => {
425428
if (options._DO_NOT_USE_beforeSignalCleanupMessage) {
426429
console.log(options._DO_NOT_USE_beforeSignalCleanupMessage)
@@ -436,7 +439,7 @@ class Executor {
436439
}
437440
}
438441

439-
const binaryPathToDelete = this.#returnBinaryPathToDelete(binaryFilepath, options)
442+
const binaryPathToDelete = this.#returnBinaryPathToDelete(installedMySQLBinary.path, options)
440443
if (binaryPathToDelete) {
441444
try {
442445
fs.rmSync(binaryPathToDelete, {force: true, recursive: true, maxRetries: 50})
@@ -455,7 +458,7 @@ class Executor {
455458
const datadir = normalizePath(`${options._DO_NOT_USE_dbPath}/data`)
456459

457460
do {
458-
await this.#setupDataDirectories(options, binaryFilepath, datadir, true);
461+
await this.#setupDataDirectories(options, installedMySQLBinary.path, datadir, true);
459462
this.logger.log('Setting up directories was successful')
460463

461464
const port = options.port || GenerateRandomPort()
@@ -464,7 +467,7 @@ class Executor {
464467

465468
try {
466469
this.logger.log('Starting MySQL process')
467-
const resolved = await this.#startMySQLProcess(options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, binaryFilepath)
470+
const resolved = await this.#startMySQLProcess(options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, installedMySQLBinary.path)
468471
this.logger.log('Starting process was successful')
469472
return resolved
470473
} catch (e) {

types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type MySQLDB = {
6363
xSocket: string,
6464
dbName: string,
6565
username: string,
66+
version: string,
6667
stop: () => Promise<void>
6768
}
6869

0 commit comments

Comments
 (0)