Skip to content
CookDex docs

Database connection

Every CookDex job works through Mealie’s API. You don’t need anything else.

On a large library, you can also give CookDex a connection to Mealie’s database. The heavy jobs then read and write in bulk instead of one recipe at a time. Jobs use the connection on their own once it’s saved. There’s no per-task switch. A job that can’t use the database carries on through the API and says why.

Measured on a test library of 12,169 recipes (Mealie v3.28 on PostgreSQL, same machine):

Job Through the API With the database
Rule tagging, preview 4.5 s (the very first run reads every recipe once: about 4 min) 3.5 s
Rule tagging, saving 20,800 new tags on 10,053 recipes about 11 min 7 s
Health check 9 s 0.4 s

Both paths find the same matches. Through the API, saving is limited by Mealie itself, which handled about 15 recipe saves a second here with a full CPU core busy. Smaller libraries, or jobs that change few recipes, won’t notice much difference.

  1. Find Mealie’s database settings in its compose file: POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_SERVER, POSTGRES_PORT and POSTGRES_DB. Or on the Mealie host:

    Terminal window
    docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' mealie
  2. In CookDex, open Settings -> Faster database access and enter them as one connection string:

    postgresql://USER:PASSWORD@SERVER:PORT/DB

    If the password has characters like @, / or :, write them as %40, %2F and %3A.

  3. Click Test connection. It reports how many recipes it found.

  4. Save.

The Docker image includes the PostgreSQL and SSH drivers.

Inside Docker, localhost is the CookDex container itself, not your server.

  • CookDex and Mealie’s Postgres on the same Docker network: use the Postgres container’s name (Mealie’s POSTGRES_SERVER, often postgres).
  • Postgres published on the host: use the host’s address and the published port.
  • Postgres only reachable from the Mealie machine: use SSH (below).

Open Connect over SSH in the same section when CookDex can’t reach the database directly. CookDex signs in to the Mealie machine and connects to the database from there. The host and port in the connection string are then as seen from that machine (often localhost:5432).

Setting Example Notes
SSH host 192.168.1.100 The Mealie machine.
SSH user your_ssh_user
SSH key file /app/.ssh/cookdex_mealie The path inside the CookDex container, not on the host.

With an SSH host set, Find and save over SSH reads Mealie’s database settings from its container and saves them straight away, along with the SSH host, user and key file it used. The connection string is saved encrypted, like any other secret, and replaces one saved before; the result says so when it does. The page shows only the host, port, database and user it found and whether there was a password. The database password itself is never shown in the browser. Click Test connection afterwards to check it.

If your Mealie uses SQLite, Find and save over SSH saves nothing and says why: the SQLite file is inside Mealie’s own container, where CookDex can’t reach it over SSH.

The setup script creates a key, installs it on the Mealie machine, mounts it into CookDex and saves the SSH settings. Run it on the machine running CookDex, Linux or macOS:

Terminal window
docker cp cookdex:/app/scripts/setup-db-tunnel.sh /tmp/setup-db-tunnel.sh && bash /tmp/setup-db-tunnel.sh

It asks for an SSH user on the Mealie machine and suggests one made only for this, cookdex-tunnel, with no sudo rights and not in the docker group; it prints the commands to create it. The key it installs can only reach the database port on the Mealie machine (localhost:5432), so use localhost as the database host. Find and save over SSH needs a user that can read Mealie’s settings; with a user that can’t, enter the connection string yourself. If an earlier version of the script installed the key for root, remove that key from /root/.ssh/authorized_keys on the Mealie machine.

Or by hand, on the machine running CookDex:

Terminal window
ssh-keygen -t ed25519 -f ~/.ssh/cookdex_mealie -N ""
ssh-copy-id -i ~/.ssh/cookdex_mealie.pub your_ssh_user@192.168.1.100

then mount it in CookDex’s compose file and recreate the container:

services:
cookdex:
volumes:
- ~/.ssh/cookdex_mealie:/app/.ssh/cookdex_mealie:ro

On Unraid there’s no compose file to edit. Make the key by hand as above, put it in a folder such as /mnt/user/appdata/cookdex/ssh, then edit the CookDex container, click Show more settings and set SSH key folder to that folder. CookDex sees it read-only as /app/.ssh, so the SSH key file setting is /app/.ssh/cookdex_mealie. Leave the field empty if you don’t use a connection over SSH.

The first time CookDex connects over SSH, it trusts the key the Mealie machine shows and writes its fingerprint in that run’s log:

Trusted 192.168.1.100's SSH host key on first connect: ssh-ed25519 SHA256:…. CookDex will refuse a different key from now on.

To check it, compare it with the fingerprint ssh-keygen -l shows for that key on the Mealie machine. If they differ, stop and find out why before you run anything else.

CookDex keeps the trusted key in ./cache/webui/known_hosts, next to its database, so it’s still there after the container is recreated. An install that already used SSH before 2026.12.1 needs nothing: its first database connection after the update trusts the key and logs the fingerprint the same way.

If the Mealie machine later shows a different key, CookDex refuses to connect. Test connection, Find and save over SSH and any job that wanted the database say:

The SSH host’s key changed since CookDex first trusted it (your_ssh_user@192.168.1.100). If the host was rebuilt, remove its line from /app/cache/webui/known_hosts and run Detect again; otherwise don’t connect.

“Detect” is the earlier name of Find and save over SSH. What to do:

  • You rebuilt or reinstalled the Mealie machine, or changed its SSH keys: delete that machine’s line from ./cache/webui/known_hosts in CookDex’s folder (the file belongs to the container’s user, so you may need sudo). Then click Find and save over SSH or Test connection. CookDex trusts the new key and logs its fingerprint.
  • You changed nothing: don’t connect. Something else is answering at that address. Jobs keep working through Mealie’s API in the meantime.

A job that can’t use the database, for any reason, finishes through Mealie’s API and tells you. Its run details list the reason under Worth a look, its log has the line

[warn] Couldn't use the database, so this run used Mealie's API instead: …

and Settings -> Faster database access shows “A job couldn’t use the database … and used Mealie’s API instead”, with the time and the reason. The note goes away when you change a database setting or Test connection works.

The reasons are the same ones Test connection and Find and save over SSH give when they fail:

Reason What to check
The SSH host’s key changed since CookDex first trusted it. See The Mealie host’s SSH key.
CookDex can’t read the SSH key file. That the key is mounted into the container and readable there.
The SSH key file can’t be used: it isn’t a private key CookDex can read, or it has a passphrase. Use a private key without a passphrase.
The SSH host refused the login. The SSH user, and that the key is in its authorized_keys.
The database refused the login. The user and password in the connection string.
Couldn’t reach the SSH host or the database. The address and port, and that it’s running. See Which host to use.

For a Mealie that uses SQLite, mount its database file into the CookDex container and use sqlite:////path/inside/container/mealie.db (four slashes for an absolute path).

Earlier versions used separate settings (MEALIE_DB_TYPE, MEALIE_PG_HOST, MEALIE_PG_PORT, MEALIE_PG_DB, MEALIE_PG_USER, MEALIE_PG_PASS, MEALIE_SQLITE_PATH) and a Use Direct DB switch on each task. Both are gone from the UI. The old settings still work: on first start CookDex combines them into one connection string (MEALIE_DB_URL) in Settings. Tasks no longer need the switch; they use the connection whenever it’s there.

CookDex uses parameterized SQL. Reads can include recipe rows, nutrition, ingredients and foods, instructions, category/tag/tool links, groups and users.

Writes are limited to the job being run:

  • yield-normalize: recipe yield and servings fields
  • slug-repair: recipe slug values
  • tag-categorize: recipe-to-tag/category/tool links, and missing tags, categories or tools when Missing Target Handling is set to create
  • clean-recipes: deleting a duplicate recipe the API can’t delete, with its related rows, in one transaction
  • reimport-recipes: repairing a slug when an older Mealie refuses an update

Database jobs still need the Mealie address and API token. They look up the API user’s group and check it matches the database before selecting recipes, and stop if it doesn’t. They never fall back to the first group in the database. Test connection checks connectivity only; a job checks scope when it runs.

Connecting doesn’t create indexes or change Mealie’s schema.

CookDex’s database tests (tests/test_db_integration.py in its source) run each database job against a fresh database built from Mealie’s own schema, once each for v3.28, v3.29, v3.30 and v3.31, on both engines. SQLite always runs; PostgreSQL runs in CI.

Behavior SQLite PostgreSQL
Deleting a recipe removes its links, ingredients and instructions; the same slug in another group is untouched; a sub-recipe line keeps its text ✓ ✓
A failed delete undoes every step, and the connection works for the next one ✓ ✓
The deduplicator’s database fallback, called from its worker threads, deletes every recipe (one transaction at a time) ✓ ✓
One failed yield update doesn’t lose the others; an update that matches no recipe counts as failed ✓ ✓
Yield updates by API recipe id, and by slug within the group ✓ ✓
Slug repair checks collisions within the recipe’s group and accepts API ids ✓ ✓
Reimport slug repair skips a slug another recipe has, and a failure doesn’t stop the next repair ✓ ✓
Tags match Mealie’s slugs (Crème Brûlée finds creme-brulee); new ids and links use the engine’s id format ✓ ✓
Recipe rows are limited to the group; the API user’s group is found from a dashed id ✓ ✓
Recipe times count in either form: Mealie’s text, or v3.29’s seconds ✓ ✓
On v3.31, which dropped the separate cook time column, the library scan reads recipe times without it ✓ ✓

Not covered: SSH tunnels, Mealie versions before v3.28, and MySQL (which Mealie doesn’t support).