feat!: absolute file paths (#19995)

feat: absolute file paths
This commit is contained in:
Jason Rasmussen 2025-07-18 10:57:29 -04:00 committed by GitHub
parent f32d4f15b6
commit 493d85b021
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 689 additions and 257 deletions

View file

@ -0,0 +1,39 @@
import { Kysely, sql } from 'kysely';
import { LoggingRepository } from 'src/repositories/logging.repository';
const logger = LoggingRepository.create();
logger.setContext('Migrations');
export async function up(db: Kysely<any>): Promise<void> {
if (process.env.IMMICH_MEDIA_LOCATION) {
// do not automatically convert paths for a custom location/setting
return;
}
// we construct paths using `path.join(mediaLocation, ...)`, which strips the leading './'
const source = 'upload';
const target = '/usr/src/app/upload';
logger.log(`Converting database file paths from relative to absolute (source=${source}/*, target=${target}/*)`);
// escaping regex special characters with a backslash
const sourceRegex = '^' + source.replaceAll(/[-[\]{}()*+?.,\\^$|#\s]/g, String.raw`\$&`);
const items: Array<{ table: string; column: string }> = [
{ table: 'asset', column: 'originalPath' },
{ table: 'asset', column: 'encodedVideoPath' },
{ table: 'asset', column: 'sidecarPath' },
{ table: 'asset_file', column: 'path' },
{ table: 'person', column: 'thumbnailPath' },
{ table: 'user', column: 'profileImagePath' },
];
for (const { table, column } of items) {
const query = `UPDATE "${table}" SET "${column}" = REGEXP_REPLACE("${column}", '${sourceRegex}', '${target}') WHERE "${column}" IS NOT NULL`;
await sql.raw(query).execute(db);
}
}
export async function down(): Promise<void> {
// not supported
}