pgserve 1.1.7-rc.2 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/postgres.js +15 -3
- package/tests/pg-version-regex.test.js +48 -0
package/package.json
CHANGED
package/src/postgres.js
CHANGED
|
@@ -965,11 +965,23 @@ export class PostgresManager {
|
|
|
965
965
|
this.logger.info('pgvector extension files not found — downloading prebuilt binary...');
|
|
966
966
|
|
|
967
967
|
try {
|
|
968
|
-
// Detect PG major version from the postgres binary
|
|
968
|
+
// Detect PG major version from the postgres binary.
|
|
969
|
+
// `postgres --version` output is `postgres (PostgreSQL) 18.2`, so the
|
|
970
|
+
// regex must tolerate the `)` that separates the product name from the
|
|
971
|
+
// version number. The previous pattern `/PostgreSQL (\d+)/` expected a
|
|
972
|
+
// digit immediately after `PostgreSQL ` and silently fell back to '17'
|
|
973
|
+
// on PG 14+, causing the wrong pgvector .deb to be downloaded and a
|
|
974
|
+
// later "incompatible library version mismatch" at CREATE EXTENSION time.
|
|
969
975
|
const { execSync } = await import('node:child_process');
|
|
970
976
|
const pgVersion = execSync(`${this.binaries.postgres} --version`, { encoding: 'utf-8' }).trim();
|
|
971
|
-
const majorMatch = pgVersion.match(/PostgreSQL
|
|
972
|
-
|
|
977
|
+
const majorMatch = pgVersion.match(/PostgreSQL\)?\s+(\d+)/);
|
|
978
|
+
if (!majorMatch) {
|
|
979
|
+
throw new Error(
|
|
980
|
+
`Could not detect PostgreSQL major version from: ${JSON.stringify(pgVersion)}`
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
const pgMajor = majorMatch[1];
|
|
984
|
+
this.logger.info({ pgMajor, pgVersion }, 'Detected PostgreSQL major version for pgvector install');
|
|
973
985
|
|
|
974
986
|
// Detect architecture — fail explicitly on unsupported platforms
|
|
975
987
|
const nodeArch = os.arch();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for pgvector auto-installer PG-major detection.
|
|
3
|
+
*
|
|
4
|
+
* `postgres --version` prints `postgres (PostgreSQL) 18.2`, so the regex that
|
|
5
|
+
* extracts the major version must tolerate the closing `)` between the
|
|
6
|
+
* product name and the number. An earlier pattern `/PostgreSQL (\d+)/`
|
|
7
|
+
* expected a digit immediately after `PostgreSQL ` and silently fell back to
|
|
8
|
+
* a hard-coded `'17'` default on PG14+, causing the wrong pgvector .deb to be
|
|
9
|
+
* downloaded and a later "incompatible library version mismatch" when
|
|
10
|
+
* `CREATE EXTENSION vector` was executed against a PG18 server.
|
|
11
|
+
*
|
|
12
|
+
* This test pins the corrected regex so the regression can't sneak back in.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { test, expect, describe } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
// Keep this in sync with `ensurePgvectorFiles()` in src/postgres.js
|
|
18
|
+
const PG_VERSION_REGEX = /PostgreSQL\)?\s+(\d+)/;
|
|
19
|
+
|
|
20
|
+
function detectMajor(versionString) {
|
|
21
|
+
const match = versionString.match(PG_VERSION_REGEX);
|
|
22
|
+
return match ? match[1] : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('PG major version detection for pgvector auto-install', () => {
|
|
26
|
+
test('parses "postgres (PostgreSQL) X.Y" format (actual postgres --version output)', () => {
|
|
27
|
+
expect(detectMajor('postgres (PostgreSQL) 18.2')).toBe('18');
|
|
28
|
+
expect(detectMajor('postgres (PostgreSQL) 17.4')).toBe('17');
|
|
29
|
+
expect(detectMajor('postgres (PostgreSQL) 16.0')).toBe('16');
|
|
30
|
+
expect(detectMajor('postgres (PostgreSQL) 14.11')).toBe('14');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('parses pre-release labels', () => {
|
|
34
|
+
expect(detectMajor('postgres (PostgreSQL) 18.2-beta.1')).toBe('18');
|
|
35
|
+
expect(detectMajor('postgres (PostgreSQL) 18devel')).toBe('18');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('parses bare "PostgreSQL X" format (no parentheses)', () => {
|
|
39
|
+
expect(detectMajor('PostgreSQL 18.2')).toBe('18');
|
|
40
|
+
expect(detectMajor('PostgreSQL 17')).toBe('17');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('returns null on unparseable input so caller can fail loudly', () => {
|
|
44
|
+
expect(detectMajor('')).toBeNull();
|
|
45
|
+
expect(detectMajor('not postgres')).toBeNull();
|
|
46
|
+
expect(detectMajor('mysql 8.0')).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
});
|