Skip to content

Commit e48f40c

Browse files
Expose whether MySQL version used for db is installed on the system or was downloaded (#163)
* add installedOnSystem boolean to DownloadedMySQLVersion type * resolve with mysql info object * add documentation * add message in cli for whether the MySQL version is already installed or not * update message * update message
1 parent ea81430 commit e48f40c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ The name of the user to use to login to the database
9898
If on Windows, this is the name of the named pipe that MySQL is listening on. If not on Windows, this is the path to the socket that MySQL is listening on.
9999
- `xSocket: string`
100100
If on Windows, this is the name of the named pipe that the MySQL X Plugin is listening on. If not on Windows, this is the path that the MySQL X Plugin is listening on.
101+
- `mysql: {version: string, versionIsInstalledOnSystem: boolean}`
102+
An object with two properties. The first one, version, is the version of MySQL Server that is being used for the database. The second one, versionIsInstalledOnSystem, will be true if the MySQL Server that is being used is already installed on the system. versionIsInstalledOnSystem will be false if the MySQL Server version had to be downloaded from the MySQL CDN.
101103
- `stop: () => Promise<void>`
102104
The method to stop the database. The returned promise resolves when the database has successfully stopped.
103105

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\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`)
42+
console.log(`A MySQL database has been successfully created with the following parameters:\n\nMySQL Version: ${db.mysql.version} (${db.mysql.versionIsInstalledOnSystem ? 'installed on this system' : 'not installed on this system - downloaded from the MySQL CDN'}) \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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function createDB(opts?: ServerOptions) {
7878
}
7979

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

src/libraries/Executor.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fsPromises from 'fs/promises';
55
import * as fs from 'fs';
66
import Logger from "./Logger";
77
import { GenerateRandomPort } from "./Port";
8-
import { ExecuteFileReturn, InstalledMySQLVersion, InternalServerOptions, MySQLDB } from "../../types";
8+
import { ExecuteFileReturn, DownloadedMySQLVersion, InternalServerOptions, MySQLDB } from "../../types";
99
import {normalize as normalizePath, resolve as resolvePath} from 'path'
1010
import { lockFile, waitForLock } from "./FileLock";
1111
import { onExit } from "signal-exit";
@@ -16,6 +16,7 @@ class Executor {
1616
DBDestroySignal = new AbortController();
1717
removeExitHandler: () => void;
1818
version: string;
19+
versionInstalledOnSystem: boolean;
1920

2021
constructor(logger: Logger) {
2122
this.logger = logger;
@@ -191,7 +192,10 @@ class Executor {
191192
xSocket,
192193
dbName: options.dbName,
193194
username: options.username,
194-
version: this.version,
195+
mysql: {
196+
version: this.version,
197+
versionIsInstalledOnSystem: this.versionInstalledOnSystem
198+
},
195199
stop: () => {
196200
return new Promise(async (resolve, reject) => {
197201
resolveFunction = resolve;
@@ -212,7 +216,7 @@ class Executor {
212216
})
213217
}
214218

215-
getMySQLVersion(preferredVersion?: string): Promise<InstalledMySQLVersion | null> {
219+
getMySQLVersion(preferredVersion?: string): Promise<DownloadedMySQLVersion | null> {
216220
return new Promise(async (resolve, reject) => {
217221
if (process.platform === 'win32') {
218222
try {
@@ -225,7 +229,7 @@ class Executor {
225229

226230
this.logger.log(servers)
227231

228-
const versions: {version: string, path: string}[] = []
232+
const versions: DownloadedMySQLVersion[] = []
229233

230234
for (const dir of servers) {
231235
const path = `${process.env.PROGRAMFILES}\\MySQL\\${dir}\\bin\\mysqld`
@@ -241,7 +245,7 @@ class Executor {
241245
if (version === null) {
242246
return reject('Could not get MySQL version')
243247
} else {
244-
versions.push({version: version.version, path})
248+
versions.push({version: version.version, path, installedOnSystem: true})
245249
}
246250
}
247251

@@ -266,7 +270,7 @@ class Executor {
266270
if (version === null) {
267271
reject('Could not get installed MySQL version')
268272
} else {
269-
resolve({version: version.version, path: 'mysqld'})
273+
resolve({version: version.version, path: 'mysqld', installedOnSystem: true})
270274
}
271275
}
272276
}
@@ -422,8 +426,9 @@ class Executor {
422426
this.logger.log('Finished writing init file')
423427
}
424428

425-
async startMySQL(options: InternalServerOptions, installedMySQLBinary: InstalledMySQLVersion): Promise<MySQLDB> {
429+
async startMySQL(options: InternalServerOptions, installedMySQLBinary: DownloadedMySQLVersion): Promise<MySQLDB> {
426430
this.version = installedMySQLBinary.version
431+
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem
427432
this.removeExitHandler = onExit(() => {
428433
if (options._DO_NOT_USE_cli) {
429434
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...')

types/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ export type MySQLDB = {
6161
xSocket: string,
6262
dbName: string,
6363
username: string,
64-
version: string,
64+
mysql: {
65+
version: string,
66+
versionIsInstalledOnSystem: boolean
67+
},
6568
stop: () => Promise<void>
6669
}
6770

@@ -73,9 +76,10 @@ export type MySQLVersion = {
7376
url: string
7477
}
7578

76-
export type InstalledMySQLVersion = {
79+
export type DownloadedMySQLVersion = {
7780
version: string,
78-
path: string
81+
path: string,
82+
installedOnSystem: boolean
7983
}
8084

8185
export type BinaryInfo = {

0 commit comments

Comments
 (0)