Skip to content

Commit 090350a

Browse files
authored
feat: add support for Postgres 14 (#7644)
1 parent 28fa716 commit 090350a

File tree

8 files changed

+73
-17
lines changed

8 files changed

+73
-17
lines changed

Diff for: .github/workflows/ci.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ jobs:
193193
- name: PostgreSQL 13, PostGIS 3.1
194194
POSTGRES_IMAGE: postgis/postgis:13-3.1
195195
NODE_VERSION: 14.18.1
196+
- name: PostgreSQL 14, PostGIS 3.1
197+
POSTGRES_IMAGE: postgis/postgis:14-3.1
198+
NODE_VERSION: 14.18.1
196199
fail-fast: false
197200
name: ${{ matrix.name }}
198201
timeout-minutes: 15
@@ -232,7 +235,9 @@ jobs:
232235
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
233236
- name: Install dependencies
234237
run: npm ci
235-
- run: bash scripts/before_script_postgres.sh
238+
- run: |
239+
bash scripts/before_script_postgres_conf.sh
240+
bash scripts/before_script_postgres.sh
236241
- run: npm run coverage
237242
env:
238243
CI: true

Diff for: CONTRIBUTING.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,23 @@ If your pull request introduces a change that may affect the storage or retrieva
145145

146146
- `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
147147
- `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
148+
- `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
149+
- `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
148150

149151
#### Postgres with Docker
150152

151153
[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:
152154

153155
```
154-
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
156+
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
155157
```
156158
To stop the Postgres instance:
157159

158160
```
159161
docker stop parse-postgres
160162
```
161163

162-
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:
164+
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:
163165

164166
```
165167
#Install additional scripts. These are run in abc order during initial start

Diff for: README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
---
44

5-
[![Build Status](https://github.com/parse-community/parse-server/workflows/ci/badge.svg?branch=master)](https://github.com/parse-community/parse-server/actions?query=workflow%3Aci+branch%3Amaster)
5+
[![Build Status](https://github.com/parse-community/parse-server/workflows/ci/badge.svg?branch=alpha)](https://github.com/parse-community/parse-server/actions?query=workflow%3Aci+branch%3Aalpha)
66
[![Snyk Badge](https://snyk.io/test/github/parse-community/parse-server/badge.svg)](https://snyk.io/test/github/parse-community/parse-server)
7-
[![Coverage](https://img.shields.io/codecov/c/github/parse-community/parse-server/master.svg)](https://codecov.io/github/parse-community/parse-server?branch=master)
7+
[![Coverage](https://img.shields.io/codecov/c/github/parse-community/parse-server/alpha.svg)](https://codecov.io/github/parse-community/parse-server?branch=alpha)
88

99
[![Node Version](https://img.shields.io/badge/nodejs-12,_14,_15-green.svg?logo=node.js&style=flat)](https://nodejs.org)
1010
[![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)
11-
[![Postgres Version](https://img.shields.io/badge/postgresql-11,_12,_13-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
11+
[![Postgres Version](https://img.shields.io/badge/postgresql-11,_12,_13,_14-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
1212
[![auto-release](https://img.shields.io/badge/%F0%9F%9A%80-auto--release-9e34eb.svg)](https://github.com/parse-community/parse-dashboard/releases)
1313

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

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

136137
### Locally
137138
```bash

Diff for: scripts/before_script_postgres_conf.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "[SCRIPT] Before Script :: Setup Parse Postgres configuration file"
6+
7+
# DB Version: 13
8+
# OS Type: linux
9+
# DB Type: web
10+
# Total Memory (RAM): 6 GB
11+
# CPUs num: 1
12+
# Data Storage: ssd
13+
14+
PGPASSWORD=postgres psql -v ON_ERROR_STOP=1 -h localhost -U postgres <<-EOSQL
15+
ALTER SYSTEM SET max_connections TO '200';
16+
ALTER SYSTEM SET shared_buffers TO '1536MB';
17+
ALTER SYSTEM SET effective_cache_size TO '4608MB';
18+
ALTER SYSTEM SET maintenance_work_mem TO '384MB';
19+
ALTER SYSTEM SET checkpoint_completion_target TO '0.9';
20+
ALTER SYSTEM SET wal_buffers TO '16MB';
21+
ALTER SYSTEM SET default_statistics_target TO '100';
22+
ALTER SYSTEM SET random_page_cost TO '1.1';
23+
ALTER SYSTEM SET effective_io_concurrency TO '200';
24+
ALTER SYSTEM SET work_mem TO '3932kB';
25+
ALTER SYSTEM SET min_wal_size TO '1GB';
26+
ALTER SYSTEM SET max_wal_size TO '4GB';
27+
SELECT pg_reload_conf();
28+
EOSQL
29+
30+
exec "$@"

Diff for: spec/.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
"notEqual": true,
1818
"it_only_db": true,
1919
"it_only_mongodb_version": true,
20+
"it_only_postgres_version": true,
2021
"fit_only_mongodb_version": true,
2122
"it_exclude_mongodb_version": true,
23+
"it_exclude_postgres_version": true,
2224
"fit_exclude_mongodb_version": true,
2325
"it_exclude_dbs": true,
2426
"describe_only_db": true,

Diff for: spec/ParseQuery.Aggregate.spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ describe('Parse.Query Aggregate testing', () => {
223223
const obj3 = new TestObject();
224224
const pipeline = [
225225
{
226-
// TODO: update to new syntax. See [#7339](https://bit.ly/3incnWx)
227-
group: {
228-
objectId: {
226+
$group: {
227+
_id: {
229228
day: { $dayOfMonth: '$_updated_at' },
230229
month: { $month: '$_created_at' },
231230
year: { $year: '$_created_at' },
@@ -254,9 +253,8 @@ describe('Parse.Query Aggregate testing', () => {
254253
const obj3 = new TestObject();
255254
const pipeline = [
256255
{
257-
// TODO: update to new syntax. See [#7339](https://bit.ly/3incnWx)
258-
group: {
259-
objectId: {
256+
$group: {
257+
_id: {
260258
day: { $dayOfMonth: '$updatedAt' },
261259
month: { $month: '$createdAt' },
262260
year: { $year: '$createdAt' },

Diff for: spec/helper.js

+18
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ global.it_only_mongodb_version = version => {
446446
}
447447
};
448448

449+
global.it_only_postgres_version = version => {
450+
const envVersion = process.env.POSTGRES_VERSION;
451+
if (!envVersion || semver.satisfies(envVersion, version)) {
452+
return it;
453+
} else {
454+
return xit;
455+
}
456+
};
457+
449458
global.fit_only_mongodb_version = version => {
450459
const envVersion = process.env.MONGODB_VERSION;
451460
if (!envVersion || semver.satisfies(envVersion, version)) {
@@ -464,6 +473,15 @@ global.it_exclude_mongodb_version = version => {
464473
}
465474
};
466475

476+
global.it_exclude_postgres_version = version => {
477+
const envVersion = process.env.POSTGRES_VERSION;
478+
if (!envVersion || !semver.satisfies(envVersion, version)) {
479+
return it;
480+
} else {
481+
return xit;
482+
}
483+
};
484+
467485
global.fit_exclude_mongodb_version = version => {
468486
const envVersion = process.env.MONGODB_VERSION;
469487
if (!envVersion || !semver.satisfies(envVersion, version)) {

Diff for: src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1983,10 +1983,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
19831983
19841984
return this._client
19851985
.one(qs, values, a => {
1986-
if (a.approximate_row_count != null) {
1987-
return +a.approximate_row_count;
1986+
if (a.approximate_row_count == null || a.approximate_row_count == -1) {
1987+
return !isNaN(+a.count) ? +a.count : 0;
19881988
} else {
1989-
return +a.count;
1989+
return +a.approximate_row_count;
19901990
}
19911991
})
19921992
.catch(error => {
@@ -2111,7 +2111,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
21112111
columns.push(
21122112
`EXTRACT(${
21132113
mongoAggregateToPostgres[operation]
2114-
} FROM $${index}:name AT TIME ZONE 'UTC') AS $${index + 1}:name`
2114+
} FROM $${index}:name AT TIME ZONE 'UTC')::integer AS $${index + 1}:name`
21152115
);
21162116
values.push(source, alias);
21172117
index += 2;

0 commit comments

Comments
 (0)