Skip to content

Commit 5b7a390

Browse files
authored
Update Postgres Indexs (#31)
* Update Postgres Indexs * update indexes
1 parent ec21697 commit 5b7a390

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Default values for environment variables: `PARSE_SERVER_APPLICATION_ID` and `PAR
139139
#### Running in production for ParseCareKit
140140
If you are plan on using parse-hipaa in production. You should run the additional scripts to create the rest of the indexes for optimized queries.
141141

142+
##### Idempotency
143+
You most likely want to enable Idempotency. Read more about how to configure on [Parse Server](https://github.com/parse-community/parse-server#idempotency-enforcement). If you are using Postgres, look [here](https://github.com/netreconlab/parse-hipaa/tree/main/postgres/scripts/parse_idempotency_delete_expired_records) for the script.
144+
142145
##### Postgres
143146
If you are using `hipaa_postgres` or `parse-postgres` (the two images included in this repo). The `setup-parse-index.sh` is already in the container. You just have to run it.
144147

postgres/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ MAINTAINER Network Reconnaissance Lab <[email protected]>
44
RUN apt-get update && apt-get install -y --no-install-recommends\
55
postgresql-$PG_MAJOR-pgaudit
66

7-
#Install additional scripts. These are run in abc order during initial start
7+
# Install additional scripts. These are run in abc order during initial start
88
COPY ./scripts/setup-0-pgaudit.sh /docker-entrypoint-initdb.d/setup-0-pgaudit.sh
99
COPY ./scripts/setup-dbs.sh /docker-entrypoint-initdb.d/setup-dbs.sh
1010
RUN chmod +x /docker-entrypoint-initdb.d/setup-0-pgaudit.sh /docker-entrypoint-initdb.d/setup-dbs.sh
1111

12-
#Install script for ParseCareKit to be run after first run
12+
# Install script for ParseCareKit to be run after first run
1313
RUN mkdir parseScripts
1414
COPY ./scripts/setup-parse-index.sh ./parseScripts/setup-parse-index.sh
1515
RUN chmod +x ./parseScripts/setup-parse-index.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
5+
SELECT idempotency_delete_expired_records();
6+
EOSQL
7+
8+
exec "$@"

postgres/scripts/setup-parse-index.sh

+18-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ set -e
44

55
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" <<-EOSQL
66
\c ${PG_PARSE_DB};
7-
CREATE INDEX IF NOT EXISTS Patient_deletedDate_is_null ON "Patient" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
8-
CREATE INDEX IF NOT EXISTS Patient_next_is_null ON "Patient" ((next IS NULL)) WHERE (next IS NULL);
9-
CREATE INDEX IF NOT EXISTS CarePlan_deletedDate_is_null ON "CarePlan" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
10-
CREATE INDEX IF NOT EXISTS CarePlan_next_is_null ON "CarePlan" ((next IS NULL)) WHERE (next IS NULL);
11-
CREATE INDEX IF NOT EXISTS Contact_deletedDate_is_null ON "Contact" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
12-
CREATE INDEX IF NOT EXISTS Contact_next_is_null ON "Contact" ((next IS NULL)) WHERE (next IS NULL);
13-
CREATE INDEX IF NOT EXISTS Task_deletedDate_is_null ON "Task" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
14-
CREATE INDEX IF NOT EXISTS Task_next_is_null ON "Task" ((next IS NULL)) WHERE (next IS NULL);
15-
CREATE INDEX IF NOT EXISTS Outcome_deletedDate_is_null ON "Outcome" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
7+
CREATE INDEX IF NOT EXISTS "Patient_deletedDate_is_null" ON "Patient" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
8+
CREATE INDEX IF NOT EXISTS "Patient_previousVersionUUIDs_array" ON "Patient" USING GIN ("previousVersionUUIDs");
9+
CREATE INDEX IF NOT EXISTS "Patient_nextVersionUUIDs_array" ON "Patient" USING GIN ("nextVersionUUIDs");
10+
CREATE INDEX IF NOT EXISTS "CarePlan_deletedDate_is_null" ON "CarePlan" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
11+
CREATE INDEX IF NOT EXISTS "CarePlan_previousVersionUUIDs_array" ON "CarePlan" USING GIN ("previousVersionUUIDs");
12+
CREATE INDEX IF NOT EXISTS "CarePlan_nextVersionUUIDs_array" ON "CarePlan" USING GIN ("nextVersionUUIDs");
13+
CREATE INDEX IF NOT EXISTS "Contact_deletedDate_is_null" ON "Contact" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
14+
CREATE INDEX IF NOT EXISTS "Contact_previousVersionUUIDs_array" ON "Contact" USING GIN ("previousVersionUUIDs");
15+
CREATE INDEX IF NOT EXISTS "Contact_nextVersionUUIDs_array" ON "Contact" USING GIN ("nextVersionUUIDs");
16+
CREATE INDEX IF NOT EXISTS "Task_deletedDate_is_null" ON "Task" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
17+
CREATE INDEX IF NOT EXISTS "Task_previousVersionUUIDs_array" ON "Task" USING GIN ("previousVersionUUIDs");
18+
CREATE INDEX IF NOT EXISTS "Task_nextVersionUUIDs_array" ON "Task" USING GIN ("nextVersionUUIDs");
19+
CREATE INDEX IF NOT EXISTS "HealthKitTask_deletedDate_is_null" ON "HealthKitTask" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
20+
CREATE INDEX IF NOT EXISTS "HealthKitTask_previousVersionUUIDs_array" ON "HealthKitTask" USING GIN ("previousVersionUUIDs");
21+
CREATE INDEX IF NOT EXISTS "HealthKitTask_nextVersionUUIDs_array" ON "HealthKitTask" USING GIN ("nextVersionUUIDs");
22+
CREATE INDEX IF NOT EXISTS "Outcome_deletedDate_is_null" ON "Outcome" (("deletedDate" IS NULL)) WHERE ("deletedDate" IS NULL);
23+
CREATE INDEX IF NOT EXISTS "Outcome_previousVersionUUIDs_array" ON "Outcome" USING GIN ("previousVersionUUIDs");
24+
CREATE INDEX IF NOT EXISTS "Outcome_nextVersionUUIDs_array" ON "Outcome" USING GIN ("nextVersionUUIDs");
1625
EOSQL
1726

1827
exec "$@"

0 commit comments

Comments
 (0)