encore icon indicating copy to clipboard operation
encore copied to clipboard

Compiler error is misleading when migrations folder is missing.

Open Willyham opened this issue 1 year ago • 0 comments

I was refactoring to break out a service, and I moved my store logic into the new service. Encore then fails with this output:

  ❌ Building Encore application graph... Failed: Invalid use of sqldb package-level function
  ⠂ Analyzing service topology...

── Invalid use of sqldb package-level function ────────────────────────────[E1699]──

The package-level query function sqldb.QueryRow can only be used within Encore
services that don't use sqldb.NewDatabase.

    ╭─[ /Users/foo/backend/checks/store.go:33:9 ]
    │
 31 │         return nil, err
 32 │     }
 33 │     row := sqldb.QueryRow(ctx, query, args...)
    ⋮            ──────────────
 34 │     if row.Err() != nil {
 35 │         return nil, row.Err()
────╯

For more information about how to use databases in Encore, see
https://encore.dev/docs/primitives/databases

I spent a while trying to understand the issue around sqldb.NewDatabase. It turns out I didn't create my migrations folder in the new service yet, and then I'm guessing Encore assumes you must be using sqldb.NewDatabase (even though I don't use it anywhere).

So technically correct, but a bit misleading. It would be nice to capture the case where sqldb.QueryX functions are used, there's no sqldb.NewDatabase call and there's no migrations folder, and offer the choice to the user. E.g. "Either create a migrations folder or use a named database".

Willyham avatar Oct 30 '23 06:10 Willyham