Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding special characters in db config #304

Merged
merged 3 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,60 @@ jobs:
- run:
name: test
command: npm run migrate up -- -m test/migrations && npm run migrate down 0 -- -m test/migrations --timestamps
test-config:
docker:
- <<: *node-image
- image: postgres:10.4-alpine
environment:
- POSTGRES_USER=ubuntu
- POSTGRES_DB=circle_test
steps:
- <<: *restore
- run:
name: create-config
command: |
mkdir -p config
cat > config/default.json << 'EOF'
{
"db": {
"user": "ubuntu",
"host": "localhost",
"port": "5432",
"database": "circle_test"
}
}
EOF
- run:
name: test
command: npm run migrate up -- -m test/migrations && npm run migrate down 0 -- -m test/migrations --timestamps
test-password:
docker:
- <<: *node-image
- image: postgres:10.4-alpine
environment:
- POSTGRES_USER=ubuntu
- POSTGRES_PASSWORD=@#$%123456abcdefghABCDEFGH{}[]\(\)/\`~,\;:.\<\>
- POSTGRES_DB=circle_test
steps:
- <<: *restore
- run:
name: create-config
command: |
mkdir -p config
cat > config/default.json << 'EOF'
{
"db": {
"user": "ubuntu",
"password": "@#$%123456abcdefghABCDEFGH{}[]()/`~,;:.<>",
"host": "localhost",
"port": "5432",
"database": "circle_test"
}
}
EOF
- run:
name: test
command: npm run migrate up -- -m test/migrations && npm run migrate down 0 -- -m test/migrations --timestamps

workflows:
version: 2
Expand All @@ -154,3 +208,9 @@ workflows:
- test-node-6:
requires:
- install
- test-config:
requires:
- install
- test-password:
requires:
- install
10 changes: 6 additions & 4 deletions bin/node-pg-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ function readJson(json) {
if (json.url) {
DATABASE_URL = json.url;
} else if (json.host || json.port || json.name || json.database) {
const password = json.password ? `:${json.password}` : "";
const credentials = `${json.user}${password}`;
const creds = credentials ? `${credentials}@` : "";
const password = json.password
? `:${encodeURIComponent(json.password)}`
: "";
const user = json.user ? encodeURIComponent(json.user) : "";
const creds = user || password ? `${user}${password}@` : "";
const host = json.host || "localhost";
const port = json.port || 5432;
const db = json.name || json.database;
const db = encodeURIComponent(json.name || json.database);
DATABASE_URL = `postgres://${creds}${host}:${port}/${db}`;
}
} else {
Expand Down
Empty file added echo
Empty file.