在 postgres 数据库中初始化 Node 微服务表的最佳实践是什么?它应该在服务启动时吗?
我正在考虑将所有 .sql 文件复制到容器(在 docker 构建期间)+ 将 psql 安装到该容器中,并且仅在 npm 启动之前在 docker run 期间运行 .sql 文件。这有意义吗?
我需要考虑的事实是,很快我还需要为微服务管理升级数据库的表。
最佳答案
一种可能是 Docker Postgres 镜像推荐的:
How to extend this image
If you would like to do additional initialization in an image derived from this one, add one or more
*.sql
or*.sh
scripts under/docker-entrypoint-initdb.d
(creating the directory if necessary).After the entrypoint calls
initdb
to create the default postgres user and database, it will run any*.sql
files and source any*.sh
scripts found in that directory to do further initialization before starting the service.
关于node.js - 如何使用在 docker 中运行的 Node 在微服务架构中初始化 postgres 数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37243939/