Skip to content

Commit

Permalink
docs: add sql-query test environment documentation (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Nov 3, 2024
1 parent 48f7c29 commit c4aa04d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/developer/sql-test-environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## Local setup for SQL query testing

### Requirements

- Docker
- HTTP Client of your choice
- Access to ghcr.io with permissions for Aam Digital private repositories

### Start containers

Take a look into the `docker-compose.yml` and adapt the file if necessary.

If you're on an ARM based system, you need to enable for the SQS container:

- `platform: linux/amd64`

#### Authorization ghcr.io
SQS is not open source and only available to developers of the Aam Digital team through a private docker image.

You will need to do a `docker login` for ghcr.io, to be able to fetch sqs image.

See [GitHub Documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry) for details.

### Access CouchDb web interface

You can access the CouchDb webinterface here: http://localhost:5984/_utils/

The default credentials are:

username: `admin`
password: `docker`

### Using existing Database

If you have a copy from an existing database, stop the couchdb container and just copy all files from the `couchdb/data` directory
into your mapped couchdb volume.
The default mapping is: `~/docker-volumes/aam-digital/db-couch/document-data:/opt/couchdb/data`

Then start the couchdb container again. Nothing more to do.

### Running SQL queries against SQS

To run a Query, you can use the POST endpoint: `http://localhost:4984/app/_design/sqlite:config`

Note that the query payload you send here is _not_ the ReportConfig entity used within Aam Digital but the raw SQS payload as shown in the example below.

#### Authentication

You need to set a 'basic auth' Authorization-Header with the couchdb credentials.

#### Example

```curl
## Example Request
curl -X "POST" "http://localhost:4984/app/_design/sqlite:config" \
-H 'Content-Type: application/json; charset=utf-8' \
-u 'admin:docker' \
-d $'{
"query": "SELECT count(*) FROM School",
"args": []
}'
```
27 changes: 27 additions & 0 deletions docs/developer/sql-test-environment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ***************************************************************
# start local development environment for SQL query testing
# ***************************************************************
name: aam-services-sql-environment
services:
db-couch:
image: couchdb:3.4
volumes:
- ~/docker-volumes/aam-digital/db-couch/document-data:/opt/couchdb/data
environment:
COUCHDB_USER: admin
COUCHDB_PASSWORD: docker
COUCHDB_SECRET: docker
ports:
- "5984:5984"

sqs:
image: ghcr.io/aam-digital/aam-sqs-linux:latest
# platform: linux/amd64
depends_on:
- db-couch
ports:
- "4984:4984"
volumes:
- ~/docker-volumes/aam-digital/sqs/data:/data
environment:
SQS_COUCHDB_URL: http://db-couch:5984

0 comments on commit c4aa04d

Please sign in to comment.