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

PRMT-4568 - ehr-repository - Remove PostgreSQL Implementation and Sequelize Dependencies #73

Merged
merged 67 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
135ae52
[PRMT-4565] store a working version of dynamodb localstack setup.
joefong-nhs Mar 3, 2024
b71df2e
[PRMT-4565] add basic test for dynamodb client
joefong-nhs Mar 4, 2024
d6747b9
[PRMT-4565] minor change in config, small change to generate_secure_s…
joefong-nhs Mar 4, 2024
41ec33a
[PRMT-4565] Read dynamodb table name from SSM, change the table name …
joefong-nhs Mar 4, 2024
15e8a1c
[PRMDR-4565] Replace localstack with dynamodb-local for running dynam…
joefong-nhs Mar 4, 2024
50afcd4
[PRMT-4565] Change timestamp format to include timezone offset
joefong-nhs Mar 5, 2024
fee2d4f
[PRMT-4566] add new version of updateFragmentAndCreateItsParts, start…
joefong-nhs Mar 5, 2024
6f3fbc6
[PRMT-4566] Config test setup and teardown
joefong-nhs Mar 5, 2024
9e332ee
[PRMT-4566] Add option to query specific record type
joefong-nhs Mar 5, 2024
554bec9
[PRMT-4566] Add state enums
joefong-nhs Mar 5, 2024
1fac37f
[PRMT-4566] separate client and repository layer
joefong-nhs Mar 5, 2024
68ef951
[PRMT-4566] Reorganise new codes
joefong-nhs Mar 5, 2024
ff53598
[PRMT-4566] Add terraform iam policy for accessing the ehr-transfer-t…
joefong-nhs Mar 6, 2024
590c11f
[PRMT-4566] Reorganise code, use CreatedAt instead of UpdatedAt to de…
joefong-nhs Mar 6, 2024
45bc5e3
[PRMT-4566] Migrate all tests in message-repository.integration.test.…
joefong-nhs Mar 6, 2024
047d5f1
[PRMT-4566] Rename test files
joefong-nhs Mar 6, 2024
8189fac
[PRMT-4566] Continue migrating database methods and integration tests…
joefong-nhs Mar 6, 2024
8b7bfda
[PRMT-4566] Migrating integrated test for more methods
joefong-nhs Mar 6, 2024
8a6cfd4
PRMT-4566 reorganise code
joefong-nhs Mar 7, 2024
88892de
[PRMT-4566] Migrated all database-related integration tests. Store cu…
joefong-nhs Mar 7, 2024
afdacf5
[PRMT-4566] Rename tests files
joefong-nhs Mar 7, 2024
7471043
[PRMT-4566] Rename methods to avoid import conflict, add deprecated m…
joefong-nhs Mar 7, 2024
1226420
[PRMT-4566] Rename methods
joefong-nhs Mar 7, 2024
d0b6a3d
[PRMT-4566] minor change in wordings
joefong-nhs Mar 7, 2024
85778d7
[PRMT-4566] Correct dynamodb related env vars
joefong-nhs Mar 7, 2024
54f9d94
[PRMT-4566] Change DeletedAt field to store ttl time of 8 weeks later
joefong-nhs Mar 11, 2024
9196cf5
[PRMT-4567] Migrated store-message-controller.js and its tests
joefong-nhs Mar 7, 2024
d78e32c
[PRMT-4567] migrated message-location-controller.js and its tests
joefong-nhs Mar 7, 2024
745f4ab
[PRMT-4567] migrated app integration tests for POST /messages endpoint
joefong-nhs Mar 7, 2024
3f3cf46
[PRMT-4567] rename test files
joefong-nhs Mar 7, 2024
7e9850b
[PRMT-4567] Migrate get-fragment-controller.js and integration tests …
joefong-nhs Mar 7, 2024
931d788
[PRMT-4567] migrated endpoint `GET /patients/:nhsNumber` and controll…
joefong-nhs Mar 8, 2024
e331497
[PRMT-4567] Migrate controller `src/api/patients/health-record-contro…
joefong-nhs Mar 8, 2024
f434d6d
[PRMT-4567] minor clean up
joefong-nhs Mar 8, 2024
b0ed972
[PRMT-4567] migrated controller delete-ehr-controller.js
joefong-nhs Mar 8, 2024
01d2c7e
[PRMT-4567] Add integration test for endpoint DELETE /patients/:nhsNu…
joefong-nhs Mar 8, 2024
ab7a6ef
[PRMT-4567] Remove postgres db checking from health check endpoint
joefong-nhs Mar 8, 2024
f73316d
[PRMR-4567] Unplug postgres db from application, comment out redundan…
joefong-nhs Mar 8, 2024
0733d83
[PRMT-4567] mark redundant tests as deprecated, fix unit tests
joefong-nhs Mar 8, 2024
a56548c
[PRMT-4567] Update dtest.yml, remove postgresdb healthcheck from dock…
joefong-nhs Mar 8, 2024
f489be2
[PRMT-4567] comment out postgresdb migration command in ./tasks
joefong-nhs Mar 8, 2024
9590886
[PRMT-4567] minor bugfix
joefong-nhs Mar 8, 2024
95c3ad5
[PRMT-4567] Update README for the change related to database and inte…
joefong-nhs Mar 8, 2024
8ba39db
[PRMR-4567] improve configs about running integration test with dojo
joefong-nhs Mar 8, 2024
a493867
[PRMT-4567] Fix test related to DeletedAt timestamp
joefong-nhs Mar 11, 2024
515de1d
[PRMT-4567] Amend Layer sort key prefix to be all capital case
joefong-nhs Mar 11, 2024
5c021a2
[PRMT-4567] use the string "STORED_IN_REPOSITORY" for complete status…
joefong-nhs Mar 11, 2024
6d1ffac
[PRMT-4567] Fixed an issue related to DeletedAt time and DST
joefong-nhs Mar 11, 2024
e349466
[PRMT-4568] Remove postgres-db related code
joefong-nhs Mar 11, 2024
0bba6ef
[PRMT-4568] Continue removing postgres-db related code
joefong-nhs Mar 11, 2024
dea9bd4
[PRMT-4568] Remove redundant comments
joefong-nhs Mar 11, 2024
176538b
[PRMT-4568] Fix broken import of deprecated code
joefong-nhs Mar 11, 2024
1289881
[PRMT-4568] Remove postgres related packages from dependencies
joefong-nhs Mar 11, 2024
e2b731a
[PRMT-4568] Remove postgresdb from docker config, remove .sequelizerc
joefong-nhs Mar 11, 2024
025ccc8
[PRMT-4568] Continue removing postgres-db related stuffs
joefong-nhs Mar 11, 2024
420a672
[PRMT-4568] Remove postgres db related content from ./tasks (except t…
joefong-nhs Mar 11, 2024
1beb507
[PRMT-4568] Run linter and formatter
joefong-nhs Mar 11, 2024
d1b5e7a
[PRMT-4568] Remove commented out code
joefong-nhs Mar 11, 2024
3066b80
[PRMT-4568] remove sequelize from package.json
joefong-nhs Mar 11, 2024
9140ce1
[PRMT-4568] Fix Dockerfile (remove references to deleted file)
joefong-nhs Mar 12, 2024
e7181ad
[PRMT-4568] remove db:migrate from package.json
joefong-nhs Mar 12, 2024
5540d9c
[PRMT-4568] Use underscore instead of hyphen in terraform code
joefong-nhs Mar 12, 2024
0871dcd
[PRMT-4568] Remove trailing comma
joefong-nhs Mar 12, 2024
d6a1d72
[PRMT-4568] Fix typo
joefong-nhs Mar 12, 2024
e2f7fd9
[PRMT-4568] fix typo (Outbound --> OUTBOUND) at TransferStatus
joefong-nhs Mar 13, 2024
432319e
[PRMT-4568] Adapt to database schema change: sort key for core change…
joefong-nhs Mar 13, 2024
4a9db22
[PRMT-4568] address PR comments
joefong-nhs Mar 14, 2024
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: 0 additions & 7 deletions .sequelizerc

This file was deleted.

11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM node:16.19.0-alpine AS builder

# install python and postgres native requirements
# install python native requirements
RUN apk update && \
apk add --no-cache bash tini postgresql-client && \
apk add --no-cache bash tini && \
rm -rf /var/cache/apk/*

RUN apk add --no-cache \
Expand All @@ -14,7 +14,7 @@ RUN apk add --no-cache \
&& rm -rf /var/cache/apk/*

# Install sequelize postgress native dependencies
RUN apk add --no-cache postgresql-dev g++ make
RUN apk add --no-cache g++ make

COPY package*.json /app/

Expand All @@ -31,10 +31,10 @@ COPY --from=builder /usr/local/bin/node /usr/local/bin
# take native-install node modules
COPY --from=builder /app /app

# install python and postgres native requirements (again, as per builder)
# install python native requirements (again, as per builder)
# add root CA from deductions team to trusted certificates
RUN apk update && \
apk add --no-cache openssl ca-certificates bash tini postgresql-client && \
apk add --no-cache openssl ca-certificates bash tini && \
rm -rf /var/cache/apk/*

RUN apk add --no-cache \
Expand All @@ -48,7 +48,6 @@ RUN apk add --no-cache \
COPY build/ /app/build
COPY database/ /app/database
COPY build/config/database.js /app/src/config/
COPY .sequelizerc /app/

COPY scripts/load-api-keys.sh /app/scripts/load-api-keys.sh
COPY scripts/run-server-with-db.sh /usr/bin/run-ehr-server
Expand Down
47 changes: 17 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ The stored the EHR is composed of the messages sent from its previous holder in
- [Docker](https://docs.docker.com/install/)
- [kudulab/dojo](https://github.com/kudulab/dojo#installation)

In order to run npm install locally on your host (outside of dojo), you'll need to install postgresql:
```
brew install postgresql
```

### AWS helpers

This repository imports shared AWS helpers from [prm-deductions-support-infra](https://github.com/nhsconnect/prm-deductions-support-infra/).
Expand All @@ -31,45 +26,37 @@ If you would like to run the app locally outside `dojo`, you need to:
```
- `NHS_ENVIRONMENT` - should be set to current environment in which the container is deployed. The name must also exist in the `database.json` file.
- `S3_BUCKET_NAME` - the name of S3 bucket to store the EHR fragments in.
- `DATABASE_USER` - username for the database
- `DATABASE_PASSWORD` - password to the database
- `DATABASE_NAME` - name of the database on server.
- `DATABASE_HOST` - database server hostname to connect with.
- `LOCALSTACK_URL` - (Test) the location of localstack, only used for tests
- `LOCALSTACK_URL` - (Test) the location of localstack, only used for s3 related tests
- `DYNAMODB_NAME` - The table name of the dynamodb table (ehr-transfer-tracker) used
```

## Running the tests

Run the unit tests with

by entering the `dojo` container and running `./tasks _test_unit`
Run the unit tests by entering the `dojo` container and running `./tasks _test_unit`
or on your machine with `npm run test:unit`

Run the integration tests within a Dojo container

1. Run `dojo -c Dojofile-itest` which will spin up the testing container
1. Run `./tasks test_integration_shell` which will spin up the testing container
2. Run `./tasks _test_integration`

You can also run them with `npm run test:integration` but that will require some additional manual set-up:
You can also run them with `./tasks test_integration` from out of dojo.

```bash
# Brings up the local test environment
docker-compose up &

# Alternative with node-dojo (interactive)
# Requires changes to Environment Variables:
# DATABASE_HOST=db
# LOCALSTACK_URL=http://localstack:4572
dojo -c Dojofile-itest
You can also run each individual integration test separately in an IDE (assuming IntelliJ),
but that will require some additional manual set-up:

npm run test-local

# This is equivalent of:
sequelize-cli db:migrate # Runs the migration
```bash
# Config env var, spin up docker containers and enter interactive dojo environment
./tasks test_integration_shell

npm test
# If things work as expected your prompts should looks like `dojo@xxxx(node-dojo):/dojo/work$`
# inside dojo, run the below script to create a dynamodb table for integration test
scripts/create-dynamodb-table.sh

sequelize-cli db:migrate:undo:all # Undoes the migration to leave clean env
# The above script will create a test table in dynamodb-local docker image.
# The dynamodb-local is accessible at endpoint http://dynamodb-local:8000 within docker,
# or at endpoint http://localhost:4573 from out of docker.
# This should allow you to run or debug db-related integration tests from Intellij's play button.
```

## Run the coverage tests (unit test and integration test)
Expand Down
50 changes: 0 additions & 50 deletions database/migrations/20210302112415-create-health-records-table.js

This file was deleted.

61 changes: 0 additions & 61 deletions database/migrations/20210302112617-create-message-table.js

This file was deleted.

30 changes: 0 additions & 30 deletions database/migrations/20210302113224-create-health-checks-table.js

This file was deleted.

14 changes: 6 additions & 8 deletions docker-compose-dtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ services:
ehr-repo:
image: ${REPOSITORY_URI}:${IMAGE_TAG}
links:
- db:db
- localstack:localstack
- dynamodb-local:dynamodb-local
ports:
- 3000:3000
db:
image: postgres:12.1
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
localstack:
image: localstack/localstack:0.10.9
environment:
Expand All @@ -31,3 +24,8 @@ services:
volumes:
- ./scripts/create-bucket.sh:/docker-entrypoint-initaws.d/create-bucket.sh
- /var/run/docker.sock:/var/run/docker.sock
dynamodb-local:
image: amazon/dynamodb-local
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
ports:
- "4573:8000"
19 changes: 8 additions & 11 deletions docker-compose-itest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ version: '2'
services:
default:
links:
- db:db
- localstack:localstack
- dynamodb-local:dynamodb-local
ports:
- "3000:3000"
db:
image: postgres:12.1
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
ports:
- "5432:5432"
localstack:
image: localstack/localstack:0.10.9
environment:
Expand All @@ -27,4 +18,10 @@ services:
- ./scripts/create-bucket.sh:/docker-entrypoint-initaws.d/create-bucket.sh
- /var/run/docker.sock:/var/run/docker.sock
logging:
driver: none
driver: none
dynamodb-local:
image: amazon/dynamodb-local
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
ports:
- "4573:8000"

11 changes: 0 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version: '3.4'
services:
postgres:
image: postgres:12.1
ports:
- 5432:5432
expose:
- 5432
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
localstack:
image: localstack/localstack
ports:
Expand Down
Loading
Loading