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

feat: add support for Postgres 14 #7644

Merged
merged 22 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from 20 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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ jobs:
- name: PostgreSQL 13, PostGIS 3.1
POSTGRES_IMAGE: postgis/postgis:13-3.1
NODE_VERSION: 14.18.1
- name: PostgreSQL 14, PostGIS 3.1
POSTGRES_IMAGE: postgis/postgis:14-3.1
NODE_VERSION: 14.18.1
fail-fast: false
name: ${{ matrix.name }}
timeout-minutes: 15
Expand Down Expand Up @@ -232,7 +235,9 @@ jobs:
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
- name: Install dependencies
run: npm ci
- run: bash scripts/before_script_postgres.sh
- run: |
bash scripts/before_script_postgres_conf.sh
bash scripts/before_script_postgres.sh
- run: npm run coverage
env:
CI: true
Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,23 @@ If your pull request introduces a change that may affect the storage or retrieva

- `it_only_mongodb_version('>=4.4')` // will test with any version of Postgres but only with version >=4.4 of MongoDB; accepts semver notation to specify a version range
- `it_exclude_mongodb_version('<4.4')` // will test with any version of Postgres and MongoDB, excluding version <4.4 of MongoDB; accepts semver notation to specify a version range
- `it_only_postgres_version('>=13')` // will test with any version of Mongo but only with version >=13 of Postgres; accepts semver notation to specify a version range
- `it_exclude_postgres_version('<13')` // will test with any version of Postgres and MongoDB, excluding version <13 of Postgres; accepts semver notation to specify a version range

#### Postgres with Docker

[PostGIS images (select one with v2.2 or higher) on docker dashboard](https://hub.docker.com/r/postgis/postgis) is based off of the official [postgres](https://registry.hub.docker.com/_/postgres/) image and will work out-of-the-box (as long as you create a user with the necessary extensions for each of your Parse databases; see below). To launch the compatible Postgres instance, copy and paste the following line into your shell:

```
docker run -d --name parse-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password --rm postgis/postgis:11-3.0-alpine && sleep 20 && docker exec -it parse-postgres psql -U postgres -c 'CREATE DATABASE parse_server_postgres_adapter_test_database;' && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION pgcrypto; CREATE EXTENSION postgis;' -d parse_server_postgres_adapter_test_database && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis_topology;' -d parse_server_postgres_adapter_test_database
docker run -d --name parse-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password --rm postgis/postgis:13-3.1-alpine && sleep 20 && docker exec -it parse-postgres psql -U postgres -c 'CREATE DATABASE parse_server_postgres_adapter_test_database;' && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION pgcrypto; CREATE EXTENSION postgis;' -d parse_server_postgres_adapter_test_database && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis_topology;' -d parse_server_postgres_adapter_test_database
```
To stop the Postgres instance:

```
docker stop parse-postgres
```

You can also use the [postgis/postgis:11-2.5-alpine](https://hub.docker.com/r/postgis/postgis) image in a Dockerfile and copy this [script](https://github.com/parse-community/parse-server/blob/master/scripts/before_script_postgres.sh) to the image by adding the following lines:
You can also use the [postgis/postgis:13-3.1-alpine](https://hub.docker.com/r/postgis/postgis) image in a Dockerfile and copy this [script](https://github.com/parse-community/parse-server/blob/master/scripts/before_script_postgres.sh) to the image by adding the following lines:

```
#Install additional scripts. These are run in abc order during initial start
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[![Node Version](https://img.shields.io/badge/nodejs-12,_14,_15-green.svg?logo=node.js&style=flat)](https://nodejs.org)
[![MongoDB Version](https://img.shields.io/badge/mongodb-4.0,_4.2,_4.4,_5.0-green.svg?logo=mongodb&style=flat)](https://www.mongodb.com)
[![Postgres Version](https://img.shields.io/badge/postgresql-11,_12,_13-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
[![Postgres Version](https://img.shields.io/badge/postgresql-11,_12,_13,_14-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
[![auto-release](https://img.shields.io/badge/%F0%9F%9A%80-auto--release-9e34eb.svg)](https://github.com/parse-community/parse-dashboard/releases)

[![npm latest version](https://img.shields.io/npm/v/parse-server/latest.svg)](https://www.npmjs.com/package/parse-server)
Expand Down Expand Up @@ -121,7 +121,7 @@ Parse Server is continuously tested with the most recent releases of MongoDB to
|-------------|----------------|------------------|--------------------|
| MongoDB 4.0 | 4.0.27 | April 2022 | ✅ Fully compatible |
| MongoDB 4.2 | 4.2.17 | TBD | ✅ Fully compatible |
| MongoDB 4.4 | 4.4.10 | TBD | ✅ Fully compatible |
| MongoDB 4.4 | 4.4.10 | TBD | ✅ Fully compatible |
| MongoDB 5.0 | 5.0.3 | January 2024 | ✅ Fully compatible |

#### PostgreSQL
Expand All @@ -132,6 +132,7 @@ Parse Server is continuously tested with the most recent releases of PostgreSQL
| Postgres 11 | 3.0, 3.1 | November 2023 | April 2022 | ✅ Fully compatible |
| Postgres 12 | 3.1 | November 2024 | April 2023 | ✅ Fully compatible |
| Postgres 13 | 3.1 | November 2025 | April 2024 | ✅ Fully compatible |
| Postgres 14 | 3.1 | November 2026 | April 2025 | ✅ Fully compatible |

### Locally
```bash
Expand Down
30 changes: 30 additions & 0 deletions scripts/before_script_postgres_conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

echo "[SCRIPT] Before Script :: Setup Parse Postgres configuration file"

# DB Version: 13
# OS Type: linux
# DB Type: web
# Total Memory (RAM): 6 GB
# CPUs num: 1
# Data Storage: ssd

PGPASSWORD=postgres psql -v ON_ERROR_STOP=1 -h localhost -U postgres <<-EOSQL
ALTER SYSTEM SET max_connections TO '200';
ALTER SYSTEM SET shared_buffers TO '1536MB';
ALTER SYSTEM SET effective_cache_size TO '4608MB';
ALTER SYSTEM SET maintenance_work_mem TO '384MB';
ALTER SYSTEM SET checkpoint_completion_target TO '0.9';
ALTER SYSTEM SET wal_buffers TO '16MB';
ALTER SYSTEM SET default_statistics_target TO '100';
ALTER SYSTEM SET random_page_cost TO '1.1';
ALTER SYSTEM SET effective_io_concurrency TO '200';
ALTER SYSTEM SET work_mem TO '3932kB';
ALTER SYSTEM SET min_wal_size TO '1GB';
ALTER SYSTEM SET max_wal_size TO '4GB';
SELECT pg_reload_conf();
EOSQL

exec "$@"
2 changes: 2 additions & 0 deletions spec/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"notEqual": true,
"it_only_db": true,
"it_only_mongodb_version": true,
"it_only_postgres_version": true,
"fit_only_mongodb_version": true,
"it_exclude_mongodb_version": true,
"it_exclude_postgres_version": true,
"fit_exclude_mongodb_version": true,
"it_exclude_dbs": true,
"describe_only_db": true,
Expand Down
10 changes: 4 additions & 6 deletions spec/ParseQuery.Aggregate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,8 @@ describe('Parse.Query Aggregate testing', () => {
const obj3 = new TestObject();
const pipeline = [
{
// TODO: update to new syntax. See [#7339](https://bit.ly/3incnWx)
group: {
objectId: {
$group: {
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
_id: {
day: { $dayOfMonth: '$_updated_at' },
month: { $month: '$_created_at' },
year: { $year: '$_created_at' },
Expand Down Expand Up @@ -254,9 +253,8 @@ describe('Parse.Query Aggregate testing', () => {
const obj3 = new TestObject();
const pipeline = [
{
// TODO: update to new syntax. See [#7339](https://bit.ly/3incnWx)
group: {
objectId: {
$group: {
_id: {
day: { $dayOfMonth: '$updatedAt' },
month: { $month: '$createdAt' },
year: { $year: '$createdAt' },
Expand Down
18 changes: 18 additions & 0 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ global.it_only_mongodb_version = version => {
}
};

global.it_only_postgres_version = version => {
const envVersion = process.env.POSTGRES_VERSION;
if (!envVersion || semver.satisfies(envVersion, version)) {
return it;
} else {
return xit;
}
};

global.fit_only_mongodb_version = version => {
const envVersion = process.env.MONGODB_VERSION;
if (!envVersion || semver.satisfies(envVersion, version)) {
Expand All @@ -464,6 +473,15 @@ global.it_exclude_mongodb_version = version => {
}
};

global.it_exclude_postgres_version = version => {
const envVersion = process.env.POSTGRES_VERSION;
if (!envVersion || !semver.satisfies(envVersion, version)) {
return it;
} else {
return xit;
}
};

global.fit_exclude_mongodb_version = version => {
const envVersion = process.env.MONGODB_VERSION;
if (!envVersion || !semver.satisfies(envVersion, version)) {
Expand Down
9 changes: 4 additions & 5 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1980,13 +1980,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
} else {
qs = 'SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = $1';
}

return this._client
.one(qs, values, a => {
if (a.approximate_row_count != null) {
return +a.approximate_row_count;
if (a.approximate_row_count == null || a.approximate_row_count == -1) {
return !isNaN(a.count) ? +a.count : 0;
} else {
return +a.count;
return +a.approximate_row_count;
}
})
.catch(error => {
Expand Down Expand Up @@ -2111,7 +2110,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
columns.push(
`EXTRACT(${
mongoAggregateToPostgres[operation]
} FROM $${index}:name AT TIME ZONE 'UTC') AS $${index + 1}:name`
} FROM $${index}:name AT TIME ZONE 'UTC')::integer AS $${index + 1}:name`
);
values.push(source, alias);
index += 2;
Expand Down