Repository: promptfoo/promptfoo
Issue: DB migration error from 0.66.0 to 0.72.2 "SqliteError: no such column: evals.author"
Root cause: Validation Gap

Updating self-hosted promptfoo from 0.66.0 to 0.72.2 raises error:
```
Failed to read result with ID undefined from database:
SqliteError: no such column: evals.author
```

It seems like running `npm run db:migrate` inside the container is not possible because migrate.ts is not copied to the container.

If I run the following command inside the container:
```
sqlite3 /root/.promptfoo/promptfoo.db <<EOF
ALTER TABLE evals ADD COLUMN author TEXT;
EOF
```
I can manage to update server to `0.72.1`

However, after updating the server to `0.72.2`, the "Evals" tab is unable to open without any error message

We definitely need to create a migrations path within the Docker image. Thanks for flagging this.

Your manually executed migration looks correct.  Is there anything in the JS Console or Network tab when you load Evals?

It seems like /api/results/undefined returns 404

Container log:
```
│ PWD=/app                                                                                                                                                                                                                        │
│ TZ=Asia/Seoul                                                                                                                                                                                                                   │
│ AIS_AGENT_EVAL_SVC_PORT_80_TCP=tcp://172.18.113.178:80                                                                                                                                                                          │
│ Starting server...                                                                                                                                                                                                              │
│ - ready started server on 0.0.0.0:3000, url: http://localhost:3000                                                                                                                                                              │
│ Listening on port 3000 url: http://0.0.0.0:3000                                                                                                                                                                                 │
│ - warn                                                                                                                                                                                                                          │
│ metadata.metadataBase is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase      
```

Network log:
```
- https://aaa.abc.com/api/results/undefined/ -> 404 not found

```

Console log:
```
737-3a7e279222e292c4.js:1 Eval init: Fetching eval via recent
/api/results/undefined/:1     Failed to load resource: the server responded with a status of 404 ()
737-3a7e279222e292c4.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'results')
    at e (737-3a7e279222e292c4.js:1:57034)
aaa.abc.com/:1 The resource https://aaa.abc.com/_next/static/css/edcd6f0b6c902fde.css was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
aaa.abc.com/:1 The resource https://aaa.abc.com/_next/static/css/edcd6f0b6c902fde.css was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
```

`api/results/` endpoint  returned the following content:
```
{
    "data": [
        {
            "id": "eval-2024-07-24T02:14:27",
            "label": "Agent - chat (eval-2024-07-24T02:14:27)"
        },
        {
            "id": "eval-2024-07-23T01:47:28",
            "label": "eval-2024-07-23T01:47:28"
        }
    ]
}
```
However, the next HTTP request has a URL path of `api/results/undefined/`.

This issue only occurs on the self-hosted app, whereas the local installation with npm works correctly.


Hey @jay0129, thanks for digging into this. I have a fix for the `undefined` route in #1257 

Hi @typpo , thanks for fixing this. It works fine for 0.73.5.