diff --git a/.travis.yml b/.travis.yml index 74b1c58dcd..526a9e79ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ jobs: packages: - postgresql-11-postgis-3 - postgresql-11-postgis-3-scripts - env: POSTGRES_MAJOR_VERSION=11 PARSE_SERVER_TEST_DB=postgres + env: POSTGRES_MAJOR_VERSION=11 PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://localhost:5433/parse_server_postgres_adapter_test_database before_install: bash scripts/before_install_postgres.sh before_script: bash scripts/before_script_postgres.sh - stage: release diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 756a2efeab..d36da0c0ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,13 +58,18 @@ Once you have babel running in watch mode, you can start making changes to parse If your pull request introduces a change that may affect the storage or retrieval of objects, you may want to make sure it plays nice with Postgres. -* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres npm test`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L37) or use [`Docker`](#run-a-parse-postgres-with-docker). +* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L43) or use [`Docker`](#run-a-parse-postgres-with-docker). * The Postgres adapter has a special debugger that traces all the sql commands. You can enable it with setting the environment variable `PARSE_SERVER_LOG_LEVEL=debug` * If your feature is intended to only work with MongoDB, you should disable PostgreSQL-specific tests with: - `describe_only_db('mongo')` // will create a `describe` that runs only on mongoDB - `it_only_db('mongo')` // will make a test that only runs on mongo - `it_exclude_dbs(['postgres'])` // will make a test that runs against all DB's but postgres +* Similarly, if your feature is intended to only work with PostgreSQL, you should disable MongoDB-specific tests with: + + - `describe_only_db('postgres')` // will create a `describe` that runs only on postgres + - `it_only_db('postgres')` // will make a test that only runs on postgres + - `it_exclude_dbs(['mongo'])` // will make a test that runs against all DB's but mongo #### Run a Parse Postgres with Docker diff --git a/scripts/before_install_postgres.sh b/scripts/before_install_postgres.sh index f2269e1301..05485f3d6c 100755 --- a/scripts/before_install_postgres.sh +++ b/scripts/before_install_postgres.sh @@ -2,20 +2,15 @@ set -e -source ~/.nvm/nvm.sh - echo "[SCRIPT] Before Install Script :: Setup Postgres ${POSTGRES_MAJOR_VERSION}" -nvm install $NODE_VERSION -nvm use $NODE_VERSION -npm install -g greenkeeper-lockfile@1 - -sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/${POSTGRES_MAJOR_VERSION}/main/postgresql.conf - if [[ $POSTGRES_MAJOR_VERSION -lt 11 ]]; then # Setup postgres 9 or 10 + sudo sed -i 's/port = 5432/port = 5433/' /etc/postgresql/${POSTGRES_MAJOR_VERSION}/main/postgresql.conf + + # Stop the current running service sudo service postgresql stop - + # Remove correct version of postgres if [[ $POSTGRES_MAJOR_VERSION -lt 10 ]]; then sudo apt-get remove -q 'postgresql-10.*' @@ -23,14 +18,12 @@ if [[ $POSTGRES_MAJOR_VERSION -lt 11 ]]; then sudo apt-get remove -q 'postgresql-9.*' fi - sudo service postgresql start ${POSTGRES_MAJOR_VERSION} + sudo service postgresql start else - # Setup postgres 11 or higher + + #Copy defauilt hba config file and tell postgres to restart sudo cp /etc/postgresql/{10,${POSTGRES_MAJOR_VERSION}}/main/pg_hba.conf - sudo service postgresql stop - # Remove previous versions of postgres - sudo apt-get remove -q 'postgresql-9.*' 'postgresql-10.*' - sudo service postgresql start ${POSTGRES_MAJOR_VERSION} + sudo systemctl restart postgresql@${POSTGRES_MAJOR_VERSION}-main fi diff --git a/scripts/before_script_postgres.sh b/scripts/before_script_postgres.sh index c63d30de23..ec67b5142d 100755 --- a/scripts/before_script_postgres.sh +++ b/scripts/before_script_postgres.sh @@ -4,9 +4,7 @@ set -e echo "[SCRIPT] Before Script :: Setup Parse DB for Postgres ${POSTGRES_MAJOR_VERSION}" -node -e 'require("./lib/index.js")' - -psql -v ON_ERROR_STOP=1 --username "postgres" --dbname "${POSTGRES_DB}" <<-EOSQL +psql -v ON_ERROR_STOP=1 -p 5433 --username "postgres" --dbname "${POSTGRES_DB}" <<-EOSQL CREATE DATABASE parse_server_postgres_adapter_test_database; \c parse_server_postgres_adapter_test_database; CREATE EXTENSION postgis; diff --git a/spec/GridFSBucketStorageAdapter.spec.js b/spec/GridFSBucketStorageAdapter.spec.js index d4b1911b52..58905e552e 100644 --- a/spec/GridFSBucketStorageAdapter.spec.js +++ b/spec/GridFSBucketStorageAdapter.spec.js @@ -14,7 +14,7 @@ async function expectMissingFile(gfsAdapter, name) { } } -describe('GridFSBucket and GridStore interop', () => { +describe_only_db('mongo')('GridFSBucket and GridStore interop', () => { beforeEach(async () => { const gsAdapter = new GridStoreAdapter(databaseURI); const db = await gsAdapter._connect(); diff --git a/spec/ParseQuery.FullTextSearch.spec.js b/spec/ParseQuery.FullTextSearch.spec.js index 6f2bebc71a..21d1c2a2f5 100644 --- a/spec/ParseQuery.FullTextSearch.spec.js +++ b/spec/ParseQuery.FullTextSearch.spec.js @@ -1,25 +1,14 @@ 'use strict'; -const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter') - .default; -const mongoURI = - 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase'; -const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter') - .default; -const postgresURI = - 'postgres://localhost:5432/parse_server_postgres_adapter_test_database'; +const Config = require('../lib/Config'); const Parse = require('parse/node'); const request = require('../lib/request'); let databaseAdapter; const fullTextHelper = () => { - if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { - if (!databaseAdapter) { - databaseAdapter = new PostgresStorageAdapter({ uri: postgresURI }); - } - } else { - databaseAdapter = new MongoStorageAdapter({ uri: mongoURI }); - } + const config = Config.get('test'); + databaseAdapter = config.database.adapter; + const subjects = [ 'coffee', 'Coffee Shopping', diff --git a/spec/PostgresInitOptions.spec.js b/spec/PostgresInitOptions.spec.js index 956d8e543a..31caf7393e 100644 --- a/spec/PostgresInitOptions.spec.js +++ b/spec/PostgresInitOptions.spec.js @@ -2,6 +2,7 @@ const Parse = require('parse/node').Parse; const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter') .default; const postgresURI = + process.env.PARSE_SERVER_TEST_DATABASE_URI || 'postgres://localhost:5432/parse_server_postgres_adapter_test_database'; const ParseServer = require('../lib/index'); const express = require('express'); diff --git a/spec/PostgresStorageAdapter.spec.js b/spec/PostgresStorageAdapter.spec.js index e722fa4cec..0ec500cff1 100644 --- a/spec/PostgresStorageAdapter.spec.js +++ b/spec/PostgresStorageAdapter.spec.js @@ -1,6 +1,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter') .default; const databaseURI = + process.env.PARSE_SERVER_TEST_DATABASE_URI || 'postgres://localhost:5432/parse_server_postgres_adapter_test_database'; const Config = require('../lib/Config');