【发布时间】:2020-05-30 21:49:17
【问题描述】:
我想在我的本地机器上设置 Hasura 的开发环境,以复制我现有的产品(相同的表、相同的架构、相同的数据)。
- 完成此任务需要哪些步骤?
【问题讨论】:
-
使用泊坞窗?复制数据库结构/数据?更多详细信息 - 阅读有关 prostgresql 中的备份的信息?
我想在我的本地机器上设置 Hasura 的开发环境,以复制我现有的产品(相同的表、相同的架构、相同的数据)。
【问题讨论】:
我发现这个过程运行良好。
创建一个干净的空本地 postgresql 数据库和 Hasura 实例。要更新现有的本地数据库,drop it and recreate it。
从现有的 Hasura 服务器转储模式和数据(根据 @protob 的 answer,但设置了 clean_output,以便不必手动更改输出。有关详细信息,请参阅 pgdump .
curl --location --request POST 'https://example.com/v1alpha1/pg_dump' \
--header 'Content-Type: application/json' \
--header 'X-Hasura-Role: admin' \
--header 'Content-Type: text/plain' \
--header 'x-hasura-admin-secret: {SECRET}' \
--data-raw '{ "opts": ["-O", "-x","--inserts", "--schema", "public"], "clean_output": true}' > hasura-db.sql
在本地导入架构和数据:
psql -h localhost -U postgres < hasura-db.sql
本地数据库有所有迁移,因为我们复制了最新的架构,所以只需将它们标记为已应用:
# A simple `hasura migrate apply --skip-execution` may work too!
for x in $(hasura migrate status | grep "Not Present" | awk '{ print $1 }'); do
hasura migrate apply --version $x --skip-execution
done
# and confirm the updated status
hasura migrate status
现在终于使用 hasura CLI 应用 Hasura 元数据:
hasura metadata apply
享受您的新实例!
【讨论】:
【讨论】:
Hasura 有一个特殊的端点用于在 Postgres 实例上执行 pg_dump。
这是一个 CURL 请求示例:
curl --location --request POST 'https://your-remote-hasura.com/v1alpha1/pg_dump' \
--header 'Content-Type: application/json' \
--header 'X-Hasura-Role: admin' \
--header 'Content-Type: text/plain' \
--data-raw '{
"opts": ["-O", "-x","--inserts", "--schema", "public"]
}'
它以 psql 格式输出架构和数据。
您可以使用 Postman 等工具来方便地导入、测试和运行 CURL 查询。
请按照 pg_dump 文档调整所需的选项。
即上述查询使用“--inserts”选项,在输出中生成“INSERT INTO”语句。
可以将输出直接复制、粘贴和导入到 Hasura 面板 SQL 选项卡(“COPY FROM stdin”语句插入面板时会导致错误)。
http://localhost:8080/console/data/sql
在导入之前,注释掉或从查询中删除行CREATE SCHEMA public;,因为它已经存在。
您还必须在执行查询期间或之后选择要跟踪的表和关系。
如果数据量比较大,使用CLI导入可能会更好。
【讨论】: