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

docs: add sql-query test environment documentation #43

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 60 additions & 0 deletions docs/developer/sql-test-environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## 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

tomwwinter marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only help people who have access to a specific server. Did you try to use the sync UI of CouchDB Fauxton? This sometimes worked for me, sometimes I didn't get it to run 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, i never used the sync ui for that... but it could work.

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`
tomwwinter marked this conversation as resolved.
Show resolved Hide resolved

#### 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't this somehow support a public url like dev.aam-digital.com/db/couchdb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretically yes, but you will need the credentials for the couchdb instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if so, maybe we can add this as an option to the docs? Seems easier for query testing than mirroring the db locally (which also requires the admin password or full server access)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i'm already on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it's complicated. Looks like the proxy in front of the CouchDB is making trouble...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you trying at /db or directly to couch at db/couchdb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/db/couchdb - idk why its not working. Just getting some Internal Server Error from SQS, no more information

Loading