Skip to content

Commit c4be1ae

Browse files
throw if xEnabled is 'FORCE' when X Plugin is not supported
1 parent c94ac82 commit c4be1ae

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function createDB(opts?: ServerOptions) {
5656
}
5757

5858
logger.log('Running downloaded binary')
59-
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version, installedOnSystem: false})
59+
return await executor.startMySQL(options, {path: binaryFilepath, version: binaryInfo.version, installedOnSystem: false, xPluginSupported: binaryInfo.xPluginSupported})
6060
} else {
6161
logger.log(version)
6262
return await executor.startMySQL(options, version)

src/libraries/Downloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function extractBinary(url: string, archiveLocation: string, extractedLocation:
246246

247247
export function downloadBinary(binaryInfo: BinaryInfo, options: InternalServerOptions, logger: Logger): Promise<string> {
248248
return new Promise(async (resolve, reject) => {
249-
const {url, version, hostedByOracle} = binaryInfo;
249+
const {url, version} = binaryInfo;
250250
const dirpath = getInternalEnvVariable('binaryDirectoryPath')
251251
logger.log('Binary path:', dirpath)
252252
await fsPromises.mkdir(dirpath, {recursive: true})

src/libraries/Executor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { lockFile, waitForLock } from "./FileLock";
1111
import { onExit } from "signal-exit";
1212
import { randomUUID } from "crypto";
1313
import { getInternalEnvVariable } from "../constants";
14-
import etcOSRelease from "./LinuxOSRelease";
14+
import etcOSRelease, { isOnAlpineLinux } from "./LinuxOSRelease";
1515

1616
class Executor {
1717
logger: Logger;
@@ -309,7 +309,7 @@ class Executor {
309309
if (version === null) {
310310
return reject('Could not get MySQL version')
311311
} else {
312-
versions.push({version: version.version, path, installedOnSystem: true})
312+
versions.push({version: version.version, path, installedOnSystem: true, xPluginSupported: gte(this.version, '5.7.19')})
313313
}
314314
}
315315

@@ -334,7 +334,7 @@ class Executor {
334334
if (version === null) {
335335
reject('Could not get installed MySQL version')
336336
} else {
337-
resolve({version: version.version, path: 'mysqld', installedOnSystem: true})
337+
resolve({version: version.version, path: 'mysqld', installedOnSystem: true, xPluginSupported: gte(this.version, '5.7.19')})
338338
}
339339
}
340340
}
@@ -488,6 +488,13 @@ class Executor {
488488
}
489489

490490
async startMySQL(options: InternalServerOptions, installedMySQLBinary: DownloadedMySQLVersion): Promise<MySQLDB> {
491+
if (installedMySQLBinary.xPluginSupported === false && options.xEnabled === 'FORCE') {
492+
if (isOnAlpineLinux) {
493+
throw "options.xEnabled is set to 'FORCE'. You are running this package on Alpine Linux. The MySQL binaries for Alpine Linux do not support the MySQL X Plugin. If you don't want to use the MySQL X Plugin, please set options.xEnabled to 'OFF' and that will remove this error message. Otherwise, if you want MySQL X to be enabled only if it is supported (like if you run this package on a different OS), then please set options.xEnabled to 'ON'. If you must have MySQL X enabled for each database creation, please use a different OS to run this package."
494+
}
495+
throw "options.xEnabled is set to 'FORCE'. The version of MySQL you are using does not support MySQL X. If you don't want to use the MySQL X Plugin, please set options.xEnabled to 'OFF'. If you only want MySQL X to be used when supported, set options.xEnabled to 'ON'. Otherwise, if MySQL X is required, please use a different version of MySQL that supports the X plugin."
496+
}
497+
491498
this.version = installedMySQLBinary.version
492499
this.versionInstalledOnSystem = installedMySQLBinary.installedOnSystem
493500
this.removeExitHandler = onExit(() => {

src/libraries/LinuxOSRelease.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import { LinuxEtcOSRelease } from '../../types'
33

4-
const releaseDetails = {}
4+
const releaseDetails: LinuxEtcOSRelease = {}
55

66
if (process.platform === 'linux') {
77
const file = fs.readFileSync('/etc/os-release', 'utf8')
@@ -14,4 +14,6 @@ if (process.platform === 'linux') {
1414
}
1515
}
1616

17-
export default releaseDetails as LinuxEtcOSRelease;
17+
export const isOnAlpineLinux = process.platform === 'linux' && releaseDetails?.ID === 'alpine'
18+
19+
export default releaseDetails;

src/libraries/Version.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BinaryInfo, JSRuntimeVersion } from "../../types";
22
import * as os from 'os'
33
import { satisfies, coerce, lt, major, minor } from "semver";
44
import { MySQLCDNDownloadsBaseURL, DMR_MYSQL_VERSIONS, DOWNLOADABLE_MYSQL_VERSIONS, MYSQL_ARCH_SUPPORT, MYSQL_LINUX_FILE_EXTENSIONS, MYSQL_LINUX_GLIBC_VERSIONS, MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE, MYSQL_MACOS_VERSIONS_IN_FILENAME, MYSQL_MIN_OS_SUPPORT, RC_MYSQL_VERSIONS, MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS, MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64 } from "../constants";
5-
import etcOSRelease from "./LinuxOSRelease";
5+
import etcOSRelease, { isOnAlpineLinux } from "./LinuxOSRelease";
66

77
export default function getBinaryURL(versionToGet: string = "x", currentArch: string): BinaryInfo {
88
let selectedVersions = DOWNLOADABLE_MYSQL_VERSIONS.filter(version => satisfies(version, versionToGet));
@@ -59,8 +59,6 @@ export default function getBinaryURL(versionToGet: string = "x", currentArch: st
5959
throw `Your operating system is too out of date to run a version of MySQL that fits the following requirement: ${versionToGet}. The oldest version for your operating system that you would need to get a version that satisfies the version requirement is ${minVersion} but your current operating system is ${coercedOSRelease.version}. Please try changing your MySQL version requirement, updating your OS to a newer version, or if you believe this is a bug, please report this on GitHub.`
6060
}
6161

62-
const isOnAlpineLinux = process.platform === 'linux' && etcOSRelease.ID === 'alpine'
63-
6462
if (process.platform === 'linux') {
6563
if (etcOSRelease.NAME === 'Ubuntu' && etcOSRelease.VERSION_ID >= '24.04') {
6664
//Since Ubuntu >= 24.04 uses libaio1t64 instead of libaio, this package has to copy libaio1t64 into a folder that MySQL looks in for dynamically linked libraries with the filename "libaio.so.1".
@@ -92,6 +90,7 @@ export default function getBinaryURL(versionToGet: string = "x", currentArch: st
9290
const isDMR = satisfies(selectedVersion, DMR_MYSQL_VERSIONS)
9391

9492
let fileLocation: string = ''
93+
let xPluginSupported = true;
9594

9695
if (currentOS === 'win32') {
9796
fileLocation = `${major(selectedVersion)}.${minor(selectedVersion)}/mysql-${selectedVersion}${isRC ? '-rc' : isDMR ? '-dmr' : ''}-winx64.zip`
@@ -101,6 +100,7 @@ export default function getBinaryURL(versionToGet: string = "x", currentArch: st
101100
fileLocation = `${major(selectedVersion)}.${minor(selectedVersion)}/mysql-${selectedVersion}${isRC ? '-rc' : isDMR ? '-dmr' : ''}-${MYSQL_MACOS_VERSIONS_IN_FILENAME[macOSVersionNameKey]}-${currentArch === 'x64' ? 'x86_64' : 'arm64'}.tar.gz`
102101
} else if (isOnAlpineLinux) {
103102
fileLocation = `https://github.com/Sebastian-Webster/mysql-server-musl-binaries/releases/download/current/mysql-musl-${selectedVersion}-${currentArch === 'x64' ? 'x86_64' : 'arm64'}.tar.gz`
103+
xPluginSupported = false
104104
} else if (currentOS === 'linux') {
105105
const glibcObject = MYSQL_LINUX_GLIBC_VERSIONS[currentArch];
106106
const glibcVersionKeys = Object.keys(glibcObject);
@@ -124,6 +124,7 @@ export default function getBinaryURL(versionToGet: string = "x", currentArch: st
124124
return {
125125
version: selectedVersion,
126126
url: isOnAlpineLinux ? fileLocation : (MySQLCDNDownloadsBaseURL + fileLocation),
127-
hostedByOracle: !isOnAlpineLinux // Only the Alpine Linux binaries are not hosted on the MySQL CDN.
127+
hostedByOracle: !isOnAlpineLinux, // Only the Alpine Linux binaries are not hosted on the MySQL CDN.
128+
xPluginSupported
128129
}
129130
}

types/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ export type MySQLDB = {
6464
export type DownloadedMySQLVersion = {
6565
version: string,
6666
path: string,
67-
installedOnSystem: boolean
67+
installedOnSystem: boolean,
68+
xPluginSupported: boolean
6869
}
6970

7071
export type BinaryInfo = {
7172
url: string,
7273
version: string,
73-
hostedByOracle: boolean
74+
hostedByOracle: boolean,
75+
xPluginSupported: boolean
7476
}
7577

7678
export type OptionTypeChecks = {

0 commit comments

Comments
 (0)