mirror of https://github.com/immich-app/immich.git
refactor(server): version logic (#9615)
* refactor(server): version * test: better version and log checkspull/9620/head
parent
5f25f28c42
commit
1df7be8436
@ -1,163 +1,145 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import semver from 'semver';
|
||||||
|
import { POSTGRES_VERSION_RANGE, VECTORS_VERSION_RANGE, VECTOR_VERSION_RANGE } from 'src/constants';
|
||||||
|
import { getVectorExtension } from 'src/database.config';
|
||||||
import {
|
import {
|
||||||
DatabaseExtension,
|
DatabaseExtension,
|
||||||
DatabaseLock,
|
DatabaseLock,
|
||||||
|
EXTENSION_NAMES,
|
||||||
IDatabaseRepository,
|
IDatabaseRepository,
|
||||||
VectorExtension,
|
|
||||||
VectorIndex,
|
VectorIndex,
|
||||||
extName,
|
|
||||||
} from 'src/interfaces/database.interface';
|
} from 'src/interfaces/database.interface';
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
import { Version, VersionType } from 'src/utils/version';
|
|
||||||
|
type CreateFailedArgs = { name: string; extension: string; otherName: string };
|
||||||
|
type UpdateFailedArgs = { name: string; extension: string; availableVersion: string };
|
||||||
|
type RestartRequiredArgs = { name: string; availableVersion: string };
|
||||||
|
type NightlyVersionArgs = { name: string; extension: string; version: string };
|
||||||
|
type OutOfRangeArgs = { name: string; extension: string; version: string; range: string };
|
||||||
|
|
||||||
|
const EXTENSION_RANGES = {
|
||||||
|
[DatabaseExtension.VECTOR]: VECTOR_VERSION_RANGE,
|
||||||
|
[DatabaseExtension.VECTORS]: VECTORS_VERSION_RANGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
notInstalled: (name: string) => `Unexpected: The ${name} extension is not installed.`,
|
||||||
|
nightlyVersion: ({ name, extension, version }: NightlyVersionArgs) => `
|
||||||
|
The ${name} extension version is ${version}, which means it is a nightly release.
|
||||||
|
|
||||||
|
Please run 'DROP EXTENSION IF EXISTS ${extension}' and switch to a release version.
|
||||||
|
See https://immich.app/docs/guides/database-queries for how to query the database.`,
|
||||||
|
outOfRange: ({ name, extension, version, range }: OutOfRangeArgs) => `
|
||||||
|
The ${name} extension version is ${version}, but Immich only supports ${range}.
|
||||||
|
|
||||||
|
If the Postgres instance already has a compatible version installed, Immich may not have the necessary permissions to activate it.
|
||||||
|
In this case, please run 'ALTER EXTENSION UPDATE ${extension}' manually as a superuser.
|
||||||
|
See https://immich.app/docs/guides/database-queries for how to query the database.
|
||||||
|
|
||||||
|
Otherwise, please update the version of ${name} in the Postgres instance to a compatible version.`,
|
||||||
|
createFailed: ({ name, extension, otherName }: CreateFailedArgs) => `
|
||||||
|
Failed to activate ${name} extension.
|
||||||
|
Please ensure the Postgres instance has ${name} installed.
|
||||||
|
|
||||||
|
If the Postgres instance already has ${name} installed, Immich may not have the necessary permissions to activate it.
|
||||||
|
In this case, please run 'CREATE EXTENSION IF NOT EXISTS ${extension}' manually as a superuser.
|
||||||
|
See https://immich.app/docs/guides/database-queries for how to query the database.
|
||||||
|
|
||||||
|
Alternatively, if your Postgres instance has ${otherName}, you may use this instead by setting the environment variable 'DB_VECTOR_EXTENSION=${otherName}'.
|
||||||
|
Note that switching between the two extensions after a successful startup is not supported.
|
||||||
|
The exception is if your version of Immich prior to upgrading was 1.90.2 or earlier.
|
||||||
|
In this case, you may set either extension now, but you will not be able to switch to the other extension following a successful startup.
|
||||||
|
`,
|
||||||
|
updateFailed: ({ name, extension, availableVersion }: UpdateFailedArgs) => `
|
||||||
|
The ${name} extension can be updated to ${availableVersion}.
|
||||||
|
Immich attempted to update the extension, but failed to do so.
|
||||||
|
This may be because Immich does not have the necessary permissions to update the extension.
|
||||||
|
|
||||||
|
Please run 'ALTER EXTENSION ${extension} UPDATE' manually as a superuser.
|
||||||
|
See https://immich.app/docs/guides/database-queries for how to query the database.`,
|
||||||
|
restartRequired: ({ name, availableVersion }: RestartRequiredArgs) => `
|
||||||
|
The ${name} extension has been updated to ${availableVersion}.
|
||||||
|
Please restart the Postgres instance to complete the update.`,
|
||||||
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DatabaseService {
|
export class DatabaseService {
|
||||||
private vectorExt: VectorExtension;
|
|
||||||
minPostgresVersion = 14;
|
|
||||||
minVectorsVersion = new Version(0, 2, 0);
|
|
||||||
vectorsVersionPin = VersionType.MINOR;
|
|
||||||
minVectorVersion = new Version(0, 5, 0);
|
|
||||||
vectorVersionPin = VersionType.MAJOR;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(IDatabaseRepository) private databaseRepository: IDatabaseRepository,
|
@Inject(IDatabaseRepository) private databaseRepository: IDatabaseRepository,
|
||||||
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
||||||
) {
|
) {
|
||||||
this.logger.setContext(DatabaseService.name);
|
this.logger.setContext(DatabaseService.name);
|
||||||
this.vectorExt = this.databaseRepository.getPreferredVectorExtension();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.assertPostgresql();
|
const version = await this.databaseRepository.getPostgresVersion();
|
||||||
await this.databaseRepository.withLock(DatabaseLock.Migrations, async () => {
|
const current = semver.coerce(version);
|
||||||
await this.createVectorExtension();
|
if (!current || !semver.satisfies(current, POSTGRES_VERSION_RANGE)) {
|
||||||
await this.updateVectorExtension();
|
throw new Error(
|
||||||
await this.assertVectorExtension();
|
`Invalid PostgreSQL version. Found ${version}, but needed ${POSTGRES_VERSION_RANGE}. Please use a supported version.`,
|
||||||
|
|
||||||
try {
|
|
||||||
if (await this.databaseRepository.shouldReindex(VectorIndex.CLIP)) {
|
|
||||||
await this.databaseRepository.reindex(VectorIndex.CLIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await this.databaseRepository.shouldReindex(VectorIndex.FACE)) {
|
|
||||||
await this.databaseRepository.reindex(VectorIndex.FACE);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.warn(
|
|
||||||
'Could not run vector reindexing checks. If the extension was updated, please restart the Postgres instance.',
|
|
||||||
);
|
);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.DB_SKIP_MIGRATIONS !== 'true') {
|
await this.databaseRepository.withLock(DatabaseLock.Migrations, async () => {
|
||||||
await this.databaseRepository.runMigrations();
|
const extension = getVectorExtension();
|
||||||
}
|
const otherExtension =
|
||||||
});
|
extension === DatabaseExtension.VECTORS ? DatabaseExtension.VECTOR : DatabaseExtension.VECTORS;
|
||||||
}
|
const otherName = EXTENSION_NAMES[otherExtension];
|
||||||
|
const name = EXTENSION_NAMES[extension];
|
||||||
private async assertPostgresql() {
|
const extensionRange = EXTENSION_RANGES[extension];
|
||||||
const { major } = await this.databaseRepository.getPostgresVersion();
|
|
||||||
if (major < this.minPostgresVersion) {
|
|
||||||
throw new Error(`
|
|
||||||
The PostgreSQL version is ${major}, which is older than the minimum supported version ${this.minPostgresVersion}.
|
|
||||||
Please upgrade to this version or later.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createVectorExtension() {
|
|
||||||
try {
|
try {
|
||||||
await this.databaseRepository.createExtension(this.vectorExt);
|
await this.databaseRepository.createExtension(extension);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const otherExt =
|
this.logger.fatal(messages.createFailed({ name, extension, otherName }));
|
||||||
this.vectorExt === DatabaseExtension.VECTORS ? DatabaseExtension.VECTOR : DatabaseExtension.VECTORS;
|
|
||||||
this.logger.fatal(`
|
|
||||||
Failed to activate ${extName[this.vectorExt]} extension.
|
|
||||||
Please ensure the Postgres instance has ${extName[this.vectorExt]} installed.
|
|
||||||
|
|
||||||
If the Postgres instance already has ${extName[this.vectorExt]} installed, Immich may not have the necessary permissions to activate it.
|
|
||||||
In this case, please run 'CREATE EXTENSION IF NOT EXISTS ${this.vectorExt}' manually as a superuser.
|
|
||||||
See https://immich.app/docs/guides/database-queries for how to query the database.
|
|
||||||
|
|
||||||
Alternatively, if your Postgres instance has ${extName[otherExt]}, you may use this instead by setting the environment variable 'DB_VECTOR_EXTENSION=${extName[otherExt]}'.
|
|
||||||
Note that switching between the two extensions after a successful startup is not supported.
|
|
||||||
The exception is if your version of Immich prior to upgrading was 1.90.2 or earlier.
|
|
||||||
In this case, you may set either extension now, but you will not be able to switch to the other extension following a successful startup.
|
|
||||||
`);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async updateVectorExtension() {
|
|
||||||
const [version, availableVersion] = await Promise.all([
|
|
||||||
this.databaseRepository.getExtensionVersion(this.vectorExt),
|
|
||||||
this.databaseRepository.getAvailableExtensionVersion(this.vectorExt),
|
|
||||||
]);
|
|
||||||
if (version == null) {
|
|
||||||
throw new Error(`Unexpected: ${extName[this.vectorExt]} extension is not installed.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (availableVersion == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const maxVersion = this.vectorExt === DatabaseExtension.VECTOR ? this.vectorVersionPin : this.vectorsVersionPin;
|
|
||||||
const isNewer = availableVersion.isNewerThan(version);
|
|
||||||
if (isNewer == null || isNewer > maxVersion) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const availableVersion = await this.databaseRepository.getAvailableExtensionVersion(extension);
|
||||||
|
if (availableVersion && semver.satisfies(availableVersion, extensionRange)) {
|
||||||
try {
|
try {
|
||||||
this.logger.log(`Updating ${extName[this.vectorExt]} extension to ${availableVersion}`);
|
this.logger.log(`Updating ${name} extension to ${availableVersion}`);
|
||||||
const { restartRequired } = await this.databaseRepository.updateVectorExtension(this.vectorExt, availableVersion);
|
const { restartRequired } = await this.databaseRepository.updateVectorExtension(extension, availableVersion);
|
||||||
if (restartRequired) {
|
if (restartRequired) {
|
||||||
this.logger.warn(`
|
this.logger.warn(messages.restartRequired({ name, availableVersion }));
|
||||||
The ${extName[this.vectorExt]} extension has been updated to ${availableVersion}.
|
|
||||||
Please restart the Postgres instance to complete the update.`);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.warn(`
|
this.logger.warn(messages.updateFailed({ name, extension, availableVersion }));
|
||||||
The ${extName[this.vectorExt]} extension version is ${version}, but ${availableVersion} is available.
|
|
||||||
Immich attempted to update the extension, but failed to do so.
|
|
||||||
This may be because Immich does not have the necessary permissions to update the extension.
|
|
||||||
|
|
||||||
Please run 'ALTER EXTENSION ${this.vectorExt} UPDATE' manually as a superuser.
|
|
||||||
See https://immich.app/docs/guides/database-queries for how to query the database.`);
|
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async assertVectorExtension() {
|
const version = await this.databaseRepository.getExtensionVersion(extension);
|
||||||
const version = await this.databaseRepository.getExtensionVersion(this.vectorExt);
|
if (!version) {
|
||||||
if (version == null) {
|
throw new Error(messages.notInstalled(name));
|
||||||
throw new Error(`Unexpected: The ${extName[this.vectorExt]} extension is not installed.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version.isEqual(new Version(0, 0, 0))) {
|
if (semver.eq(version, '0.0.0')) {
|
||||||
throw new Error(`
|
throw new Error(messages.nightlyVersion({ name, extension, version }));
|
||||||
The ${extName[this.vectorExt]} extension version is ${version}, which means it is a nightly release.
|
|
||||||
|
|
||||||
Please run 'DROP EXTENSION IF EXISTS ${this.vectorExt}' and switch to a release version.
|
|
||||||
See https://immich.app/docs/guides/database-queries for how to query the database.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const minVersion = this.vectorExt === DatabaseExtension.VECTOR ? this.minVectorVersion : this.minVectorsVersion;
|
if (!semver.satisfies(version, extensionRange)) {
|
||||||
const maxVersion = this.vectorExt === DatabaseExtension.VECTOR ? this.vectorVersionPin : this.vectorsVersionPin;
|
throw new Error(messages.outOfRange({ name, extension, version, range: extensionRange }));
|
||||||
|
}
|
||||||
if (version.isOlderThan(minVersion) || version.isNewerThan(minVersion) > maxVersion) {
|
|
||||||
const allowedReleaseType = maxVersion === VersionType.MAJOR ? '' : ` ${VersionType[maxVersion].toLowerCase()}`;
|
|
||||||
const releases =
|
|
||||||
maxVersion === VersionType.EQUAL
|
|
||||||
? minVersion.toString()
|
|
||||||
: `${minVersion} and later${allowedReleaseType} releases`;
|
|
||||||
|
|
||||||
throw new Error(`
|
try {
|
||||||
The ${extName[this.vectorExt]} extension version is ${version}, but Immich only supports ${releases}.
|
if (await this.databaseRepository.shouldReindex(VectorIndex.CLIP)) {
|
||||||
|
await this.databaseRepository.reindex(VectorIndex.CLIP);
|
||||||
|
}
|
||||||
|
|
||||||
If the Postgres instance already has a compatible version installed, Immich may not have the necessary permissions to activate it.
|
if (await this.databaseRepository.shouldReindex(VectorIndex.FACE)) {
|
||||||
In this case, please run 'ALTER EXTENSION UPDATE ${this.vectorExt}' manually as a superuser.
|
await this.databaseRepository.reindex(VectorIndex.FACE);
|
||||||
See https://immich.app/docs/guides/database-queries for how to query the database.
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(
|
||||||
|
'Could not run vector reindexing checks. If the extension was updated, please restart the Postgres instance.',
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
Otherwise, please update the version of ${extName[this.vectorExt]} in the Postgres instance to a compatible version.`);
|
if (process.env.DB_SKIP_MIGRATIONS !== 'true') {
|
||||||
|
await this.databaseRepository.runMigrations();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,72 +0,0 @@
|
|||||||
import { Version, VersionType } from 'src/utils/version';
|
|
||||||
|
|
||||||
describe('Version', () => {
|
|
||||||
const tests = [
|
|
||||||
{ this: new Version(0, 0, 1), other: new Version(0, 0, 0), compare: 1, type: VersionType.PATCH },
|
|
||||||
{ this: new Version(0, 1, 0), other: new Version(0, 0, 0), compare: 1, type: VersionType.MINOR },
|
|
||||||
{ this: new Version(1, 0, 0), other: new Version(0, 0, 0), compare: 1, type: VersionType.MAJOR },
|
|
||||||
{ this: new Version(0, 0, 0), other: new Version(0, 0, 1), compare: -1, type: VersionType.PATCH },
|
|
||||||
{ this: new Version(0, 0, 0), other: new Version(0, 1, 0), compare: -1, type: VersionType.MINOR },
|
|
||||||
{ this: new Version(0, 0, 0), other: new Version(1, 0, 0), compare: -1, type: VersionType.MAJOR },
|
|
||||||
{ this: new Version(0, 0, 0), other: new Version(0, 0, 0), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(0, 0, 1), other: new Version(0, 0, 1), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(0, 1, 0), other: new Version(0, 1, 0), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(1, 0, 0), other: new Version(1, 0, 0), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(1, 0), other: new Version(1, 0, 0), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(1, 0), other: new Version(1, 0, 1), compare: -1, type: VersionType.PATCH },
|
|
||||||
{ this: new Version(1, 1), other: new Version(1, 0, 1), compare: 1, type: VersionType.MINOR },
|
|
||||||
{ this: new Version(1), other: new Version(1, 0, 0), compare: 0, type: VersionType.EQUAL },
|
|
||||||
{ this: new Version(1), other: new Version(1, 0, 1), compare: -1, type: VersionType.PATCH },
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('isOlderThan', () => {
|
|
||||||
for (const { this: thisVersion, other: otherVersion, compare, type } of tests) {
|
|
||||||
const expected = compare < 0 ? type : VersionType.EQUAL;
|
|
||||||
it(`should return '${expected}' when comparing ${thisVersion} to ${otherVersion}`, () => {
|
|
||||||
expect(thisVersion.isOlderThan(otherVersion)).toEqual(expected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isEqual', () => {
|
|
||||||
for (const { this: thisVersion, other: otherVersion, compare } of tests) {
|
|
||||||
const bool = compare === 0;
|
|
||||||
it(`should return ${bool} when comparing ${thisVersion} to ${otherVersion}`, () => {
|
|
||||||
expect(thisVersion.isEqual(otherVersion)).toEqual(bool);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isNewerThan', () => {
|
|
||||||
for (const { this: thisVersion, other: otherVersion, compare, type } of tests) {
|
|
||||||
const expected = compare > 0 ? type : VersionType.EQUAL;
|
|
||||||
it(`should return ${expected} when comparing ${thisVersion} to ${otherVersion}`, () => {
|
|
||||||
expect(thisVersion.isNewerThan(otherVersion)).toEqual(expected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('fromString', () => {
|
|
||||||
const tests = [
|
|
||||||
{ scenario: 'leading v', value: 'v1.72.2', expected: new Version(1, 72, 2) },
|
|
||||||
{ scenario: 'uppercase v', value: 'V1.72.2', expected: new Version(1, 72, 2) },
|
|
||||||
{ scenario: 'missing v', value: '1.72.2', expected: new Version(1, 72, 2) },
|
|
||||||
{ scenario: 'large patch', value: '1.72.123', expected: new Version(1, 72, 123) },
|
|
||||||
{ scenario: 'large minor', value: '1.123.0', expected: new Version(1, 123, 0) },
|
|
||||||
{ scenario: 'large major', value: '123.0.0', expected: new Version(123, 0, 0) },
|
|
||||||
{ scenario: 'major bump', value: 'v2.0.0', expected: new Version(2, 0, 0) },
|
|
||||||
{ scenario: 'has dash', value: '14.10-1', expected: new Version(14, 10, 1) },
|
|
||||||
{ scenario: 'missing patch', value: '14.10', expected: new Version(14, 10, 0) },
|
|
||||||
{ scenario: 'only major', value: '14', expected: new Version(14, 0, 0) },
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const { scenario, value, expected } of tests) {
|
|
||||||
it(`should correctly parse ${scenario}`, () => {
|
|
||||||
const actual = Version.fromString(value);
|
|
||||||
expect(actual.major).toEqual(expected.major);
|
|
||||||
expect(actual.minor).toEqual(expected.minor);
|
|
||||||
expect(actual.patch).toEqual(expected.patch);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
export type IVersion = { major: number; minor: number; patch: number };
|
|
||||||
|
|
||||||
export enum VersionType {
|
|
||||||
EQUAL = 0,
|
|
||||||
PATCH = 1,
|
|
||||||
MINOR = 2,
|
|
||||||
MAJOR = 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Version implements IVersion {
|
|
||||||
public readonly types = ['major', 'minor', 'patch'] as const;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
public major: number,
|
|
||||||
public minor: number = 0,
|
|
||||||
public patch: number = 0,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
return `${this.major}.${this.minor}.${this.patch}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON() {
|
|
||||||
const { major, minor, patch } = this;
|
|
||||||
return { major, minor, patch };
|
|
||||||
}
|
|
||||||
|
|
||||||
static fromString(version: string): Version {
|
|
||||||
const regex = /v?(?<major>\d+)(?:\.(?<minor>\d+))?(?:[.-](?<patch>\d+))?/i;
|
|
||||||
const matchResult = version.match(regex);
|
|
||||||
if (matchResult) {
|
|
||||||
const { major, minor = '0', patch = '0' } = matchResult.groups as { [K in keyof IVersion]: string };
|
|
||||||
return new Version(Number(major), Number(minor), Number(patch));
|
|
||||||
} else {
|
|
||||||
throw new Error(`Invalid version format: ${version}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private compare(version: Version): [number, VersionType] {
|
|
||||||
for (const [i, key] of this.types.entries()) {
|
|
||||||
const diff = this[key] - version[key];
|
|
||||||
if (diff !== 0) {
|
|
||||||
return [diff > 0 ? 1 : -1, (VersionType.MAJOR - i) as VersionType];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [0, VersionType.EQUAL];
|
|
||||||
}
|
|
||||||
|
|
||||||
isOlderThan(version: Version): VersionType {
|
|
||||||
const [bool, type] = this.compare(version);
|
|
||||||
return bool < 0 ? type : VersionType.EQUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
isEqual(version: Version): boolean {
|
|
||||||
const [bool] = this.compare(version);
|
|
||||||
return bool === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
isNewerThan(version: Version): VersionType {
|
|
||||||
const [bool, type] = this.compare(version);
|
|
||||||
return bool > 0 ? type : VersionType.EQUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
compareTo(other: Version) {
|
|
||||||
if (this.isEqual(other)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.isNewerThan(other) ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue