From 7d07aaeba394e4ae633742224ccc95f8abe88b5d Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:25:15 +0200 Subject: [PATCH] chore(docs): Some SQL queries to copy paste for advanced debugging (#4074) * enable sql code highlighting, first queries * remove tabs * something with moons... * feat: more queries --------- Co-authored-by: Jason Rasmussen --- docs/docs/guides/database-queries.md | 81 ++++++++++++++++++++++++++++ docs/docs/guides/docker-help.md | 4 -- docs/docs/guides/machine-learning.md | 2 +- docs/docusaurus.config.js | 1 + 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 docs/docs/guides/database-queries.md diff --git a/docs/docs/guides/database-queries.md b/docs/docs/guides/database-queries.md new file mode 100644 index 000000000..e8be92ef4 --- /dev/null +++ b/docs/docs/guides/database-queries.md @@ -0,0 +1,81 @@ +# Database Queries + +:::danger +Keep in mind that mucking around in the database might set the moon on fire. Avoid modifying the database directly when possible, and always have current backups. +::: + +:::tip +Run `docker exec -it immich_postgres psql immich ` to connect to the database via the container directly. + +(Replace `` wit the value from your [`.env` file](/docs/install/environment-variables#database)). +::: + +## Assets + +:::note +The `"originalFileName"` column is the name of the uploaded file _without_ the extension. +::: + +```sql title="Find by original filename" +SELECT * FROM "assets" WHERE "originalFileName" = 'PXL_20230903_232542848'; +SELECT * FROM "assets" WHERE "originalFileName" LIKE 'PXL_%'; -- all files starting with PXL_ +SELECT * FROM "assets" WHERE "originalFileName" LIKE '%_2023_%'; -- all files with _2023_ in the middle +``` + +```sql title="Find by path" +SELECT * FROM "assets" WHERE "originalPath" = 'upload/library/admin/2023/2023-09-03/PXL_20230903_232542848.jpg'; +SELECT * FROM "assets" WHERE "originalPath" LIKE 'upload/library/admin/2023/%'; +``` + +```sql title="Find by checksum" (sha1) +SELECT encode("checksum", 'hex') FROM "assets"; +SELECT * FROM "assets" WHERE "checksum" = decode('69de19c87658c4c15d9cacb9967b8e033bf74dd1', 'hex'); +``` + +```sql title="Live photos" +SELECT * FROM "assets" where "livePhotoVideoId" IS NOT NULL; +``` + +```sql title="Without metadata" +SELECT "assets".* FROM "exif" LEFT JOIN "assets" ON "assets"."id" = "exif"."assetId" WHERE "exif"."assetId" IS NULL; +``` + +```sql title="Without thumbnails" +SELECT * FROM "assets" WHERE "assets"."resizePath" IS NULL OR "assets"."webpPath" IS NULL; +``` + +```sql title="By type" +SELECT * FROM "assets" WHERE "assets"."type" = 'VIDEO'; +SELECT * FROM "assets" WHERE "assets"."type" = 'IMAGE'; +``` + +```sql title="Count by type" +SELECT "assets"."type", count(*) FROM "assets" GROUP BY "assets"."type"; +``` + +```sql title="Count by type (per user)" +SELECT + "users"."email", "assets"."type", COUNT(*) +FROM + "assets" +JOIN + "users" ON "assets"."ownerId" = "users"."id" +GROUP BY + "assets"."type", "users"."email" +ORDER BY + "users"."email"; +``` + +## Users + +```sql title="List" +SELECT * FROM "users"; +``` + +## System Config + +```sql title="Custom settings" +SELECT "key", "value" FROM "system_config"; +``` + +(Only used when not using the [config file](/docs/install/config-file)) diff --git a/docs/docs/guides/docker-help.md b/docs/docs/guides/docker-help.md index e85d62258..7ea0f6d67 100644 --- a/docs/docs/guides/docker-help.md +++ b/docs/docs/guides/docker-help.md @@ -1,7 +1,3 @@ ---- -sidebar_position: 1 ---- - # Docker Help ## Containers diff --git a/docs/docs/guides/machine-learning.md b/docs/docs/guides/machine-learning.md index 14fafb962..f16c23a1e 100644 --- a/docs/docs/guides/machine-learning.md +++ b/docs/docs/guides/machine-learning.md @@ -1,4 +1,4 @@ -# Hosting the machine-learning service on another system +# Remote Machine Learning To alleviate [performance issues on low-memory systems](/docs/FAQ.md#why-is-immich-slow-on-low-memory-systems-like-the-raspberry-pi) like the Raspberry Pi, you may also host Immich's machine-learning container on a more powerful system (e.g. your laptop or desktop computer): diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index db7331cd0..92f7a641d 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -161,6 +161,7 @@ const config = { prism: { theme: lightCodeTheme, darkTheme: darkCodeTheme, + additionalLanguages: ['sql'], }, image: 'overview/img/feature-panel.png', }),