Skip to content

Commit

Permalink
expose MySQL version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Webster committed Nov 29, 2024
1 parent 0368f65 commit 4798888
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function main() {
}
console.log('Creating ephemeral MySQL database...')
const db = await createDB(options);
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`)
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`)
if (process.platform === 'win32') {
//The connection information logs will be different for Windows compared to other platforms.
//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.
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export async function createDB(opts?: ServerOptions) {
}

logger.log('Running downloaded binary')
return await executor.startMySQL(options, binaryFilepath)
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version})
} else {
logger.log(version)
return await executor.startMySQL(options, version.path)
return await executor.startMySQL(options, version)
}
}
13 changes: 8 additions & 5 deletions src/libraries/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { randomUUID } from "crypto";
class Executor {
logger: Logger;
DBDestroySignal = new AbortController();
removeExitHandler: () => void
removeExitHandler: () => void;
version: string;

constructor(logger: Logger) {
this.logger = logger;
Expand Down Expand Up @@ -190,6 +191,7 @@ class Executor {
xSocket,
dbName: options.dbName,
username: options.username,
version: this.version,
stop: () => {
return new Promise(async (resolve, reject) => {
resolveFunction = resolve;
Expand Down Expand Up @@ -420,7 +422,8 @@ class Executor {
this.logger.log('Finished writing init file')
}

async startMySQL(options: InternalServerOptions, binaryFilepath: string): Promise<MySQLDB> {
async startMySQL(options: InternalServerOptions, installedMySQLBinary: InstalledMySQLVersion): Promise<MySQLDB> {
this.version = installedMySQLBinary.version
this.removeExitHandler = onExit(() => {
if (options._DO_NOT_USE_beforeSignalCleanupMessage) {
console.log(options._DO_NOT_USE_beforeSignalCleanupMessage)
Expand All @@ -436,7 +439,7 @@ class Executor {
}
}

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

do {
await this.#setupDataDirectories(options, binaryFilepath, datadir, true);
await this.#setupDataDirectories(options, installedMySQLBinary.path, datadir, true);
this.logger.log('Setting up directories was successful')

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

try {
this.logger.log('Starting MySQL process')
const resolved = await this.#startMySQLProcess(options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, binaryFilepath)
const resolved = await this.#startMySQLProcess(options, port, mySQLXPort, datadir, options._DO_NOT_USE_dbPath, installedMySQLBinary.path)
this.logger.log('Starting process was successful')
return resolved
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type MySQLDB = {
xSocket: string,
dbName: string,
username: string,
version: string,
stop: () => Promise<void>
}

Expand Down

0 comments on commit 4798888

Please sign in to comment.