Home > Mobile >  Migrating datbase using SQLC from Docker not working
Migrating datbase using SQLC from Docker not working

Time:09-14

I am trying to generate database migrations using SQLC over Windows OS. According to the official documentation I need to run the Docker command (because it supports Postgres over Windows).

If I run docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate from a CLI it works. But if I run make sqlc it displays an error:

docker run --rm -v ":/src" -w /src kjconroy/sqlc generate

error parsing configuration files. sqlc.yaml or sqlc.json: file does not exist

make: *** [Makefile:12: sqlc] Error 1

I have my folder structure like this:

  • app/
    • db/
      • migration/
      • query/
        • myquery.sql
      • sqlc/
    • sqlc.yaml
    • Makefile

My sqlc.yaml file has this:

version: "1"
packages:
    - name: "db"
      path: "./db/sqlc"
      queries: "./db/query"
      schema: "./db/migration/"
      engine: "postgresql"
      emit_json_tags: true
      emit_prepared_queries: false
      emit_interface: false
      emit_exact_table_names: false

And Makefile this:

sqlc:
    docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate

.PHONY: sqlc

So, how to make it work from the Makefile? I am not getting the error here? Maybe the field mapping is wrong?

CodePudding user response:

The error sqlc.yaml or sqlc.json: file does not exist simply means that sqlc (running in a container) is not finding the sqlc.yaml file in /src. When starting the container you are mapping ${pwd} to /src so the issue is that ${pwd} is not evaluating to the app/db folder as you expect it to. This is could be due to either:

In your case (based on your comment) it's the former and changing ${pwd} to ${CURDIR} fixes the issue.

  • Related