mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Server: Fixes #10532: Fix PostgreSQL version check failing on Windows Server because wrong regex (#11038)
This commit is contained in:
parent
b61467097d
commit
8b4e163b28
46
packages/server/src/db.test.ts
Normal file
46
packages/server/src/db.test.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { DbConnection, versionCheck } from './db';
|
||||
import { } from './env';
|
||||
import { DatabaseConfigClient } from './utils/types';
|
||||
|
||||
describe('db', () => {
|
||||
|
||||
const mockedDb = (version: string, client: DatabaseConfigClient = DatabaseConfigClient.PostgreSQL) => {
|
||||
return {
|
||||
select: () => {
|
||||
return {
|
||||
first: () => ({
|
||||
version,
|
||||
}),
|
||||
};
|
||||
}
|
||||
,
|
||||
raw: () => '',
|
||||
client: {
|
||||
config: { client },
|
||||
},
|
||||
} as unknown as DbConnection;
|
||||
};
|
||||
|
||||
it.each(
|
||||
[
|
||||
'PostgreSQL 15.3 (Debian 15.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit',
|
||||
'PostgreSQL 16.3, compiled by Visual C++ build 1938, 64-bit"',
|
||||
],
|
||||
)('should handle versionCheck on all known string versions', (versionDescription: string) => {
|
||||
|
||||
expect(versionCheck(mockedDb(versionDescription))).resolves.toBe(undefined);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'PostgreSQL 11.16 (Debian 11.16-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit',
|
||||
])('should throw because it is a outdated version', (versionDescription: string) => {
|
||||
|
||||
expect(versionCheck(mockedDb(versionDescription))).rejects.toThrow(`Postgres version not supported: ${versionDescription}. Min required version is: 12.0`);
|
||||
});
|
||||
|
||||
it('should not check version if client is not SQLite', () => {
|
||||
const sqliteDb = mockedDb('invalid version', DatabaseConfigClient.SQLite);
|
||||
|
||||
expect(versionCheck(sqliteDb)).resolves.toBe(undefined);
|
||||
});
|
||||
});
|
@ -453,7 +453,7 @@ export function isUniqueConstraintError(error: any): boolean {
|
||||
|
||||
const parsePostgresVersionString = (versionString: string) => {
|
||||
// PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
|
||||
const matches = versionString.match('PostgreSQL (.*?) ');
|
||||
const matches = versionString.match(/PostgreSQL ([0-9.]+)/);
|
||||
if (!matches || matches.length !== 2) throw new Error(`Cannot parse Postgres version string: ${versionString}`);
|
||||
return matches[1];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user