mirror of
https://github.com/immich-app/immich.git
synced 2025-08-07 09:04:09 -04:00
fix: automatic media location migration without internal assets (#20489)
This commit is contained in:
parent
c3263e50fc
commit
3cdc6844a1
@ -170,27 +170,10 @@ where
|
|||||||
|
|
||||||
-- AssetRepository.getFileSamples
|
-- AssetRepository.getFileSamples
|
||||||
select
|
select
|
||||||
"asset"."id",
|
"assetId",
|
||||||
"asset"."originalPath",
|
"path"
|
||||||
"asset"."sidecarPath",
|
|
||||||
"asset"."encodedVideoPath",
|
|
||||||
(
|
|
||||||
select
|
|
||||||
coalesce(json_agg(agg), '[]')
|
|
||||||
from
|
|
||||||
(
|
|
||||||
select
|
|
||||||
"path"
|
|
||||||
from
|
|
||||||
"asset_file"
|
|
||||||
where
|
|
||||||
"asset"."id" = "asset_file"."assetId"
|
|
||||||
) as agg
|
|
||||||
) as "files"
|
|
||||||
from
|
from
|
||||||
"asset"
|
"asset_file"
|
||||||
where
|
|
||||||
"asset"."libraryId" is null
|
|
||||||
limit
|
limit
|
||||||
3
|
3
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Insertable, Kysely, NotNull, Selectable, UpdateResult, Updateable, sql } from 'kysely';
|
import { Insertable, Kysely, NotNull, Selectable, UpdateResult, Updateable, sql } from 'kysely';
|
||||||
import { jsonArrayFrom } from 'kysely/helpers/postgres';
|
|
||||||
import { isEmpty, isUndefined, omitBy } from 'lodash';
|
import { isEmpty, isUndefined, omitBy } from 'lodash';
|
||||||
import { InjectKysely } from 'nestjs-kysely';
|
import { InjectKysely } from 'nestjs-kysely';
|
||||||
import { Stack } from 'src/database';
|
import { Stack } from 'src/database';
|
||||||
@ -338,20 +337,7 @@ export class AssetRepository {
|
|||||||
|
|
||||||
@GenerateSql()
|
@GenerateSql()
|
||||||
getFileSamples() {
|
getFileSamples() {
|
||||||
return this.db
|
return this.db.selectFrom('asset_file').select(['assetId', 'path']).limit(sql.lit(3)).execute();
|
||||||
.selectFrom('asset')
|
|
||||||
.select((eb) => [
|
|
||||||
'asset.id',
|
|
||||||
'asset.originalPath',
|
|
||||||
'asset.sidecarPath',
|
|
||||||
'asset.encodedVideoPath',
|
|
||||||
jsonArrayFrom(eb.selectFrom('asset_file').select('path').whereRef('asset.id', '=', 'asset_file.assetId')).as(
|
|
||||||
'files',
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.where('asset.libraryId', 'is', null)
|
|
||||||
.limit(sql.lit(3))
|
|
||||||
.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
|
@ -86,12 +86,7 @@ export class CliService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const asset of assets) {
|
for (const asset of assets) {
|
||||||
paths.push(
|
paths.push(asset.path);
|
||||||
asset.originalPath,
|
|
||||||
asset.sidecarPath,
|
|
||||||
asset.encodedVideoPath,
|
|
||||||
...asset.files.map((file) => file.path),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths.filter(Boolean) as string[];
|
return paths.filter(Boolean) as string[];
|
||||||
|
@ -97,18 +97,18 @@ export class StorageService extends BaseService {
|
|||||||
const current = StorageCore.getMediaLocation();
|
const current = StorageCore.getMediaLocation();
|
||||||
const samples = await this.assetRepository.getFileSamples();
|
const samples = await this.assetRepository.getFileSamples();
|
||||||
if (samples.length > 0) {
|
if (samples.length > 0) {
|
||||||
const originalPath = samples[0].originalPath;
|
const path = samples[0].path;
|
||||||
const savedValue = await this.systemMetadataRepository.get(SystemMetadataKey.MediaLocation);
|
const savedValue = await this.systemMetadataRepository.get(SystemMetadataKey.MediaLocation);
|
||||||
let previous = savedValue?.location || '';
|
let previous = savedValue?.location || '';
|
||||||
|
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
previous = originalPath.startsWith('upload/') ? 'upload' : '/usr/src/app/upload';
|
previous = path.startsWith('upload/') ? 'upload' : '/usr/src/app/upload';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous !== current) {
|
if (previous !== current) {
|
||||||
this.logger.log(`Media location changed (from=${previous}, to=${current})`);
|
this.logger.log(`Media location changed (from=${previous}, to=${current})`);
|
||||||
|
|
||||||
if (!originalPath.startsWith(previous)) {
|
if (!path.startsWith(previous)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Detected an inconsistent media location. For more information, see https://immich.app/errors#inconsistent-media-location',
|
'Detected an inconsistent media location. For more information, see https://immich.app/errors#inconsistent-media-location',
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user