Skip to content

Commit a516b1b

Browse files
authored
Merge pull request #739 from OpenKnowledgeMaps/database-migration
Database migration
2 parents 585db25 + 5f6a52f commit a516b1b

68 files changed

Lines changed: 4283 additions & 514 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
server/preprocessing/other-scripts/.Rhistory
2-
server/preprocessing/other-scripts/renv
3-
/nbproject/private/
4-
/server/nbproject/private/
51
*_local.*
62
vis/images/*.pdf
73
node_modules/
@@ -12,14 +8,7 @@ vis/stylesheets/*.css
128
dist/
139
.idea/
1410
/config.js
15-
*__pycache__*
16-
.pytest_cache
1711
.cache
18-
.Rhistory
19-
.ipynb_checkpoints
20-
*.ipynb
21-
.Rprofile
22-
.Rproj*
2312
coverage/
2413

2514
# local deployment files
@@ -36,9 +25,39 @@ coverage/
3625
/lc_cache.json
3726
/linkedcat.sqlite
3827
.env
39-
*.env
40-
.Rproj.user
28+
backend_*.sh
29+
server/workers/tests/*.csv
30+
server/workers/tests/*.txt
31+
server/workers/tests/testutils/
4132

42-
# PHP dev env files
33+
# php files
34+
/server/classes/headstart/vendor
4335
/server/classes/headstart/var/*
44-
/server/classes/headstart/vendor/*
36+
37+
# R files
38+
server/preprocessing/other-scripts/.Rhistory
39+
server/preprocessing/other-scripts/renv
40+
.Rhistory
41+
.Rprofile
42+
.Rproj*
43+
.Rproj.user
44+
45+
# python files
46+
*.pyc
47+
*.pkl
48+
.ipynb_checkpoints
49+
*.ipynb
50+
/nbproject/private/
51+
/server/nbproject/private/
52+
.pytest_cache
53+
*__pycache__*
54+
55+
# python files
56+
*.pyc
57+
*.pkl
58+
.ipynb_checkpoints
59+
*.ipynb
60+
/nbproject/private/
61+
/server/nbproject/private/
62+
.pytest_cache
63+
*__pycache__*

docker-compose-end2endtest.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# docker-compose-end2endtest.yml
2+
3+
version: '3.7'
4+
services:
5+
6+
end2endtest:
7+
build:
8+
context: ./server/workers/tests
9+
dockerfile: ./Dockerfile_tests
10+
container_name: end2endtest
11+
hostname: "end2endtest"
12+
environment:
13+
POSTGRES_USER: "testuser"
14+
POSTGRES_PASSWORD: "testpassword"
15+
POSTGRES_HOST: "test_db"
16+
POSTGRES_PORT: 5432
17+
DEFAULT_DATABASE: "testdb"
18+
SERVICE_VERSION: "test_version"
19+
ports:
20+
- "0.0.0.0:5000:5000"
21+
volumes:
22+
- ./server/:/app
23+
depends_on:
24+
- db
25+
- backend
26+
restart: "no"
27+
entrypoint: [ "pytest", '/app/workers/tests/test_end2end.py', '-s', '-rfA']
28+
networks:
29+
test:
30+
ipv4_address: 172.18.0.2
31+
32+
backend:
33+
container_name: backend
34+
hostname: "backend"
35+
build:
36+
context: ./server/workers/tests
37+
dockerfile: ./Dockerfile_backend
38+
volumes:
39+
- ./server/:/var/www/html/server
40+
restart: "no"
41+
networks:
42+
test:
43+
ipv4_address: 172.18.0.3
44+
ports:
45+
- "80:80"
46+
47+
db:
48+
container_name: test_db
49+
image: 'postgres:12.2-alpine'
50+
restart: "no"
51+
hostname: "db_server"
52+
environment:
53+
POSTGRES_USER: "testuser"
54+
POSTGRES_PASSWORD: "testpassword"
55+
POSTGRES_HOST: "db_server"
56+
POSTGRES_PORT: 5432
57+
DEFAULT_DATABASE: "testdb"
58+
command: postgres -c config_file=/etc/postgresql.conf -c hba_file=/etc/pg_hba.conf
59+
volumes:
60+
# - db_data:/var/lib/postgresql/data
61+
- ./server/workers/tests/test_data/pg_hba_test_local.conf:/etc/pg_hba.conf
62+
- ./server/workers/tests/test_data/postgresql_test_local.conf:/etc/postgresql.conf
63+
ports:
64+
- "5432:5432"
65+
networks:
66+
test:
67+
ipv4_address: 172.18.0.4
68+
69+
volumes:
70+
db_data:
71+
72+
networks:
73+
test:
74+
driver: bridge
75+
ipam:
76+
config:
77+
- subnet: 172.18.0.0/16
78+
gateway: 172.18.0.1

docker-compose-phptest.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# docker-compose-phptest.yml
2+
3+
version: '3.7'
4+
services:
5+
composer:
6+
image: composer:2.5.8
7+
environment:
8+
- COMPOSER_CACHE_DIR=/app/var/cache/composer
9+
volumes:
10+
- ./server/classes/headstart:/app
11+
restart: never
12+
13+
phpcs:
14+
image: cytopia/phpcs:latest-php8.0
15+
restart: never
16+
volumes:
17+
- ./server:/data
18+
working_dir: /data
19+
20+
phpunit80:
21+
image: php:8.0-cli
22+
restart: never
23+
volumes:
24+
- ./server/:/app
25+
working_dir: /app/classes/headstart
26+
entrypoint: vendor/bin/phpunit
27+
28+
phpunit82:
29+
image: php:8.2-cli
30+
restart: never
31+
volumes:
32+
- ./server/classes/headstart:/app
33+
working_dir: /app
34+
entrypoint: vendor/bin/phpunit
35+

docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ services:
4343
REDIS_DB: "${REDIS_DB}"
4444
BEHIND_PROXY: "${BEHIND_PROXY}"
4545
DEFAULT_DATABASE: "${DEFAULT_DATABASE}"
46-
DATABASES: "${DATABASES}"
4746
FLASK_ENV: "${FLASK_ENV}"
4847
command: ["gunicorn", "--workers", "10", "--threads", "2", "-b", "0.0.0.0:${API_PORT}", "app:app", "--timeout", "300"]
4948
volumes:
@@ -63,12 +62,12 @@ services:
6362
SERVICE_VERSION: "${SERVICE_VERSION}"
6463
POSTGRES_USER: "${POSTGRES_USER}"
6564
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
66-
POSTGRES_HOST: "${POSTGRES_HOST}"
67-
POSTGRES_PORT: "${POSTGRES_PORT}"
65+
POSTGRES_HOSTS: "${POSTGRES_HOSTS}"
66+
POSTGRES_PORTS: "${POSTGRES_PORTS}"
6867
BEHIND_PROXY: "${BEHIND_PROXY}"
6968
DEFAULT_DATABASE: "${DEFAULT_DATABASE}"
70-
DATABASES: "${DATABASES}"
7169
FLASK_ENV: "${FLASK_ENV}"
70+
SSH_AUTH_SOCK: "/run/host-services/ssh-auth.sock"
7271
command: ["gunicorn", "--workers", "10", "--threads", "2", "-b", "0.0.0.0:${API_PORT}", "app:app", "--timeout", "300"]
7372
networks:
7473
- headstart

server/classes/headstart/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# How to run PHP unit tests with docker
2+
3+
4+
On root level of Headstart:
5+
6+
7+
* Install PHP unit 9 which works for PHP 8.0 and 8.2
8+
9+
`docker-compose -f docker-compose-phptest.yml run composer require --dev phpunit/phpunit 9 --ignore-platform-reqs`
10+
11+
* Test that PHPUnit can run for PHP versions 8.0 and 8.2
12+
13+
```
14+
docker-compose -f docker-compose-phptest.yml run phpunit80 --version
15+
docker-compose -f docker-compose-phptest.yml run phpunit82 --version
16+
```
17+
18+
Run linting
19+
20+
```
21+
docker-compose -f docker-compose-phptest.yml run phpcs ./classes/headstart/persistence/Persistence.php \
22+
./classes/headstart/persistence/SQLitePersistence.php \
23+
./services/search.php \
24+
./services/getLatestRevision.php \
25+
./services/getLastVersion.php
26+
27+
```
28+
29+
Run tests
30+
31+
```
32+
docker-compose -f docker-compose-phptest.yml run phpunit80
33+
docker-compose -f docker-compose-phptest.yml run phpunit82
34+
```
35+
36+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require-dev": {
3+
"phpunit/phpunit": "10.3.0"
4+
}
5+
}

0 commit comments

Comments
 (0)