node.js - 创建后 Postgresql 数据库在 travis ci 中不存在

标签 node.js postgresql travis-ci

将 postgresql 添加到我的应用程序后,每次我在 travis 上运行测试时,我都会收到一条错误消息,指出当我在 travis.yml 中运行 database.js 时,数据库不存在。 但我的测试在本地通过 这是我的 .yml 文件

services:
  - postgresql
before_script:
  - travis_wait 30 yarn install
  - "psql -c 'create database myDiary;' -U postgres"
  - travis_wait npm install
  - node build/models/database.js

这是我在 database.js 中的连接

const connectionString = 'postgres://postgres:password@localhost:5432/myDiary';

const client = new pg.Client(connectionString);
client.connect();

附件是我的travis输出

Travis CI 错误输出

enter image description here

最佳答案

Travis 没有创建 myDiary 数据库,因为整行都被字符串化了。只有 -c 后面的命令应该是一个字符串。

services:
  - postgresql
before_script:
  - travis_wait 30 yarn install
  - psql -c 'create database myDiary;' -U postgres
  - travis_wait npm install
  - node build/models/database.js

关于node.js - 创建后 Postgresql 数据库在 travis ci 中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51569499/

相关文章:

node.js - 使用 npm 运行 bash 脚本

javascript - console.log(JSON.parse(result)) 在我期望看到 JSON 的地方打印 [Object]

javascript - Node.js 和浏览器之间的中间件?

javascript - 这会造成任何安全漏洞吗?

mysql - 用于插入在 1 中大于最大值的值的 SQL 命令

travis-ci - 如何使用 Travis CLI 登录 Travis Enterprise?

postgresql密码验证失败

postgresql - SQL 触发器如何影响性能?

firebase - 特拉维斯和 Firebase : deploy only changed functions

ruby - 在Travis上将Elasticsearch版本指定为2.3.1