update-assets-set-local-date-time-for-three-and-seven

This commit is contained in:
2025-08-09 07:32:55 -07:00
parent c4d42d79a0
commit 895dab9413
3 changed files with 31 additions and 0 deletions

View File

@ -47,4 +47,8 @@ public class AssetsController(AssetService assetService) : ControllerBase {
public IActionResult SetDigiKam4ArchiveImmich(Guid ownerId) => public IActionResult SetDigiKam4ArchiveImmich(Guid ownerId) =>
Ok(_AssetService.SetDigiKam4ArchiveImmich(ownerId)); Ok(_AssetService.SetDigiKam4ArchiveImmich(ownerId));
[HttpGet("update-assets-set-local-date-time-for-three-and-seven")]
public IActionResult UpdateAssetsSetLocalDateTimeForThreeAndSeven() =>
Ok(_AssetService.UpdateAssetsSetLocalDateTimeForThreeAndSeven());
} }

View File

@ -242,4 +242,13 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
return results?.AsReadOnly(); return results?.AsReadOnly();
} }
public ReadOnlyCollection<int>? UpdateAssetsSetLocalDateTimeForThreeAndSeven() {
ReadOnlyCollection<int>? results;
NpgsqlParameter[] npgsqlParameters = [];
string commandText = CommandText.UpdateAssetsSetLocalDateTimeForThreeAndSeven(_Settings.LowestVersionHistory);
int? result = ExecuteNonQuery(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
results = result is null ? null : new([result.Value]);
return results?.AsReadOnly();
}
} }

View File

@ -174,4 +174,22 @@ internal static class CommandText {
return string.Join(Environment.NewLine, results); return string.Join(Environment.NewLine, results);
} // cSpell:enable } // cSpell:enable
internal static string UpdateAssetsSetLocalDateTimeForThreeAndSeven(float lowestVersionHistory) { // cSpell:disable
List<string> results = [];
if (lowestVersionHistory <= 1.129) {
results.Add(" UPDATE assets ");
} else {
results.Add(" UPDATE public.asset ");
}
results.AddRange([
" SET \"localDateTime\" = TIMESTAMPTZ(\"localDateTime\") - INTERVAL '100 years' ",
" WHERE \"localDateTime\" > TIMESTAMPTZ '1990-01-01 00:00:00-00' ",
" AND ( ",
" \"deviceAssetId\" like '%3.%' ",
" OR \"deviceAssetId\" like '%7.%' ",
" ); ",
]);
return string.Join(Environment.NewLine, results);
} // cSpell:enable
} }