Skip to content

feat(sqlite): Use new SQLite Database #553

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

Merged
merged 70 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f06fd9b
update function to get ahb table from database
hf-krechan Apr 15, 2025
44b313e
update function to get all format versions
hf-krechan Apr 15, 2025
d68d4be
WIP to update get all known prüfis
hf-krechan Apr 15, 2025
1a1f0fc
fix query for pruefis
hf-krechan Apr 15, 2025
1e92055
remove D_ from Dataelements
hf-krechan Apr 15, 2025
ac78483
update ahb line entity
hf-krechan Apr 15, 2025
236be3c
add conditions in table view
hf-krechan Apr 15, 2025
379dd87
remove duplicate SG
hf-krechan Apr 22, 2025
81f2d61
update ahb.db
hf-krechan Apr 22, 2025
981b207
put mapping into two functions
hf-krechan Apr 22, 2025
f8de608
add line_type in orm model
hf-krechan Apr 22, 2025
3a3cb86
remove unused import
hf-krechan Apr 22, 2025
1fd7262
fix segment name
hf-krechan Apr 22, 2025
c7387b8
wip column mapping
hf-krechan Apr 22, 2025
2e24554
add line_type to openapi sepc
hf-krechan Apr 22, 2025
7921fbb
remove unused import
hf-krechan Apr 22, 2025
32d2b47
generate code from openapi spec
hf-krechan Apr 22, 2025
1b7b70f
add line_type
hf-krechan Apr 22, 2025
984be3f
use line type to define border style
hf-krechan Apr 22, 2025
354befe
getting closer
hf-krechan Apr 22, 2025
7e57afd
even closer
hf-krechan Apr 22, 2025
800dd98
remove unused code sections
hf-krechan Apr 22, 2025
50fb57a
use isSegmentGroup
hf-krechan Apr 22, 2025
98b4a69
Change from data_element to data_element: thin line
hf-krechan Apr 22, 2025
10b66ca
refactor broder style matching
hf-krechan Apr 22, 2025
f6509db
use git lfs
hf-krechan Apr 22, 2025
09e84b6
change filter for lfs to *.db
hf-krechan Apr 22, 2025
7a0e44e
add fernet dependency
hf-krechan Apr 22, 2025
03af52a
use encrypted database
hf-krechan Apr 22, 2025
4fa12c3
add encrypted sqlite
hf-krechan Apr 22, 2025
8e0bbb4
ignore ahb.db
hf-krechan Apr 22, 2025
47bbe0d
use lfs true for checkouts in github actions
hf-krechan Apr 22, 2025
c98243a
ignore 7z files
hf-krechan Apr 22, 2025
2042f09
add fenret key to dev and prod stacks
hf-krechan Apr 22, 2025
e01b19f
read and set fenret key
hf-krechan Apr 22, 2025
de7d0d9
remove unused import
hf-krechan Apr 22, 2025
ffddaf4
fix linter warnings by running `ng lint --fix`
hf-krechan Apr 22, 2025
f41ab5a
set fernet key env var
hf-krechan Apr 22, 2025
057d0ca
use 7z
hf-krechan Apr 23, 2025
4311ebe
working approach 7z approach
hf-krechan Apr 23, 2025
9adfb0d
remove duplicate code
hf-krechan Apr 23, 2025
f4fff67
remove fernet encrypted ahb db
hf-krechan Apr 23, 2025
011a9a3
use new env var name to clarify
hf-krechan Apr 23, 2025
be9c5d7
remove fernet dependencies
hf-krechan Apr 23, 2025
ec6ff1f
update environment variable in pulumi
hf-krechan Apr 23, 2025
2bb2ee3
update secret for 7z archive
hf-krechan Apr 23, 2025
0c4fcc4
add environment variable for 7z archive password
hf-krechan Apr 23, 2025
955312f
update environment variable in test ci
hf-krechan Apr 23, 2025
e13dbbe
add link to secret
hf-krechan Apr 23, 2025
6ad1dd7
update file name for encrypted database
hf-krechan Apr 23, 2025
cf710ae
use 7zip-min
hf-krechan Apr 24, 2025
3271e10
feat(7z-decrypt): Use 7z in Dockerfile (#554)
hf-krechan Apr 24, 2025
a5587bc
remove 7zip-min dependency
hf-krechan Apr 24, 2025
a3b6a4f
remove gitattributes for LFS
hf-krechan Apr 24, 2025
2cb58e1
remove lfs
hf-krechan Apr 24, 2025
7a3c92c
allow 7z files again
hf-krechan Apr 24, 2025
df81e86
add 7z sqlite database
hf-krechan Apr 24, 2025
a867a83
use most recent sqlite db (contains even more segment, doesn't have t…
Apr 24, 2025
0ab90de
chore: Upgrade to Node 23.11 (#555)
hf-krechan Apr 25, 2025
265b011
clean dockerignore
hf-krechan Apr 25, 2025
d2ccb38
improve dockerfile
hf-krechan Apr 25, 2025
05614c8
add section to tell contributors that they need a password
hf-krechan Apr 25, 2025
2636e3c
update docker-compose
hf-krechan Apr 25, 2025
cf0e0d9
update example env
hf-krechan Apr 25, 2025
b73f85b
add docker environment
hf-krechan Apr 25, 2025
405baec
add docker env in bruno
hf-krechan Apr 25, 2025
28a86e4
update companystylesheet
hf-krechan Apr 25, 2025
7182cc2
add hint where the sqlite comes from
hf-krechan Apr 25, 2025
635f862
remove deprecated code lines
hf-krechan Apr 25, 2025
d8afeee
remove 7z relict
hf-krechan Apr 25, 2025
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
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_modules
/.vscode
/.nx
/.angular
.drone.yml
.editorconfig
.eslintrc.json
.git
Expand All @@ -25,4 +24,3 @@ README.md
.idea
.octopus
azure-mock
node_modules
2 changes: 2 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ AZURE_BLOB_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol='http;AccountName=
FORMAT_VERSION_CONTAINER_NAME=format-versions

OH_DEAR_HEALTH_CHECK_SECRET=my-secret-oh-dear-health-check-secret

DB_7Z_ARCHIVE_PASSWORD=my-secret-db-7z-archive-password
5 changes: 4 additions & 1 deletion .github/workflows/action_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20.13'
Expand All @@ -35,6 +34,10 @@ jobs:

- name: Unit tests
run: npm test
env:
# secret is set in organization settings
# https://github.com/organizations/Hochfrequenz/settings/secrets/actions/SQLITE_AHB_DB_7Z_ARCHIVE_PASSWORD
DB_7Z_ARCHIVE_PASSWORD: ${{ secrets.SQLITE_AHB_DB_7Z_ARCHIVE_PASSWORD }}

- name: Build frontend
run: npm run ng:build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ Thumbs.db
.nx/cache
.nx/workspace-data


src/server/data/ahb.db
3 changes: 1 addition & 2 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
v20.13

v23.11
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@ WORKDIR /service
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nodejs

# Copy all necessary files into the image
# Copy package files first for better caching
COPY package*.json ./
COPY tailwind.config.js ./

# Install dependencies
RUN npm ci --no-scripts

# Copy the rest of the application
COPY . .

# Install p7zip for 7z archive handling
RUN apk add --no-cache p7zip

# Make scripts executable
RUN chmod +x ./start.sh ./decrypt-db.sh

# Change ownership of the service folder and all copied files to the nodejs user
RUN chown -R nodejs:nodejs /service

# Install dependencies
RUN npm ci --no-scripts

# Switch to non-root user
USER nodejs

# Expose port for the server
EXPOSE 3000

# Start the application via start.sh script
CMD ["sh", "./start.sh"]
CMD ["sh", "./start.sh"]
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ $ npm install -g @angular/cli

Create an `.env` file in the root directory and paste the contents of the `.example.env` file.

> [!IMPORTANT]
> The application requires a SQLite database to function.
> This database is stored in an encrypted 7z archive at `src/server/data/ahb.db.encrypted.7z`.
> You will need the password to decrypt this archive, which can be found in the Hochfrequenz 1Password vault at [this link](https://start.1password.com/open/i?a=F35NURJ4PFGOPBA77PR66C5P4I&v=vjgfwz7dg5wg656rfpvadetrqy&i=grnjb4hn6ipcau4bqe43rkuwnq&h=hochfrequenz.1password.com).
>
> If you don't have access to the 1Password vault, please ask your teamates how to get the password.
>
> To work locally, you need to decrypt the archive and store the decrypted file in at `src/server/data/ahb.db`.
>
> If you want to start the application with Docker, you need to set the `DB_7Z_ARCHIVE_PASSWORD` environment variable in the `docker-compose.yaml` file either by setting it directly or by using the `.env` file.
> We recommend the latter to keep the `docker-compose.yaml` file clean and readable.

While having [Docker Desktop](https://www.docker.com/products/docker-desktop/) up and running, start the docker container using

```bash
Expand Down
9 changes: 9 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
}
]
},
"docker": {
"outputHashing": "all",
"fileReplacements": [
{
"replace": "src/app/environments/environment.ts",
"with": "src/app/environments/environment.docker.ts"
}
]
},
"development": {
"optimization": false,
"extractLicenses": false,
Expand Down
11 changes: 11 additions & 0 deletions bruno/Get AHB.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: Get AHB
type: http
seq: 5
}

get {
url: {{host}}/api/format-versions/FV2504/pruefis
body: none
auth: none
}
3 changes: 3 additions & 0 deletions bruno/environments/docker.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
host: http://localhost:4000
}
34 changes: 34 additions & 0 deletions decrypt-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# Exit immediately if a command exits with a non-zero status
set -e

echo "Checking if database needs to be decrypted..."

ARCHIVE_PATH="/service/src/server/data/ahb.db.encrypted.7z"
DB_PATH="/service/src/server/data/ahb.db"

if [ ! -f "$ARCHIVE_PATH" ]; then
echo "Error: 7z archive not found at $ARCHIVE_PATH"
exit 1
fi

# Only decrypt if the database doesn't exist or if the archive is newer
if [ ! -f "$DB_PATH" ] || [ "$ARCHIVE_PATH" -nt "$DB_PATH" ]; then
echo "Decrypting database from 7z archive..."
if [ -z "$DB_7Z_ARCHIVE_PASSWORD" ]; then
echo "Error: DB_7Z_ARCHIVE_PASSWORD environment variable is not set"
exit 1
fi

7z x -y -p"$DB_7Z_ARCHIVE_PASSWORD" -o"$(dirname "$DB_PATH")" "$ARCHIVE_PATH"

if [ $? -eq 0 ]; then
echo "Database decrypted successfully"
else
echo "Error: Failed to decrypt database"
exit 1
fi
else
echo "Database is up to date, no decryption needed"
fi
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ services:
- AZURE_BLOB_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10000/devstoreaccount1;
- AHB_CONTAINER_NAME=uploaded-files
- FORMAT_VERSION_CONTAINER_NAME=format-versions
- ENVIRONMENT=stage
- DB_7Z_ARCHIVE_PASSWORD=${DB_7Z_ARCHIVE_PASSWORD}
- ENVIRONMENT=docker
depends_on:
- upload-documents
- azurite
4 changes: 4 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ components:
value_pool_entry:
type: string
example: 'Entry1'
line_type:
type: string
example: 'segment'
required:
- ahb_expression
- data_element
Expand All @@ -178,6 +181,7 @@ components:
- segment_code
- segment_group_key
- value_pool_entry
- line_type
meta:
type: object
properties:
Expand Down
Loading