英文:
Migrating datbase using SQLC from Docker not working
问题
我正在尝试在Windows操作系统上使用SQLC生成数据库迁移。根据官方文档的说明,我需要运行Docker命令(因为它支持Windows上的Postgres)。
如果我在命令行中运行docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate
,它可以正常工作。但是如果我运行make sqlc
,就会显示一个错误:
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
我的文件夹结构如下:
- app/
- db/
- migration/
- query/
- myquery.sql
- sqlc/
- sqlc.yaml
- Makefile
- db/
我的sqlc.yaml
文件内容如下:
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
Makefile
文件内容如下:
sqlc:
docker run --rm -v "${pwd}:/src" -w /src kjconroy/sqlc generate
.PHONY: sqlc
那么,如何使其在Makefile中正常工作?我在这里没有得到错误信息。也许字段映射有问题?
英文:
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
- db/
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?
答案1
得分: 2
错误sqlc.yaml或sqlc.json:文件不存在
只是表示sqlc
(在容器中运行)在/src
中找不到sqlc.yaml
文件。当启动容器时,您将${pwd}
映射到/src
,所以问题是${pwd}
没有按照您的期望解析为app/db
文件夹。这可能是由于以下原因之一:
- 尝试扩展它(请参阅GNU Make文档和此问题),或者
- 它只是没有解析为db文件夹
根据您的情况(根据您的评论),是前者,将${pwd}
更改为${CURDIR}
即可解决此问题。
英文:
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:
- Make attempting to expand it (see GNU Make docs and this question) or,
- Its just not resolving to the db folder
In your case (based on your comment) it's the former and changing ${pwd}
to ${CURDIR}
fixes the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论