Skip to content

Commit cce7259

Browse files
committed
Hmm …
1 parent f7fc1ff commit cce7259

14 files changed

+80
-24
lines changed

bin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fetch-data.config
2+
# Ignore a custom compose script
3+
compose

bin/fetch-data

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,46 @@ project_dir=$(cd "$(dirname "$script_dir")" && pwd)
77

88
cd "$project_dir"
99

10-
database_urls=(
11-
# Cf. ../docker-compose.override.yml
12-
'mysql://db:db@database-0:3306/db?serverVersion=10.11.2-MariaDB&charset=utf8mb4'
13-
'mysql://db:db@database-1:3306/db?serverVersion=10.11.2-MariaDB&charset=utf8mb4'
14-
)
10+
config_file="$script_dir/fetch-data.config"
1511

16-
current_database_url=$(docker compose exec phpfpm bin/console debug:config DoctrineBundle --resolve-env --format=json | docker compose run --rm jq '.doctrine.dbal.connections.default.url' --raw-output)
12+
if [ ! -e "$config_file" ]; then
13+
(>&2 echo "Config file $config_file does not exists")
14+
15+
exit 1
16+
fi
17+
18+
# shellcheck source=fetch-data.config
19+
source "$config_file"
20+
21+
if [ -z "${database_urls:-}" ]; then
22+
cat <<EOF >&2
23+
Missing
24+
25+
database_urls=(…)
26+
27+
in $config_file.
28+
29+
EOF
30+
31+
exit 1
32+
fi
33+
34+
# https://www.php.net/manual/en/reserved.constants.php#constant.php-int-max
35+
max=${max:-9223372036854775807}
36+
page_size=${page_size:-1000}
37+
38+
echo max: "$max"
39+
echo page_size: "$page_size"
40+
41+
function compose() {
42+
if [[ -n "${compose_script:-}" ]]; then
43+
"$compose_script" "$@"
44+
else
45+
docker compose "$@"
46+
fi
47+
}
48+
49+
current_database_url=$(compose exec phpfpm bin/console debug:config DoctrineBundle --resolve-env --format=json | compose run --rm jq '.doctrine.dbal.connections.default.url' --raw-output)
1750

1851
current_index=-1
1952
for i in "${!database_urls[@]}"; do
@@ -31,13 +64,12 @@ echo current_index: "$current_index"
3164
echo next_database_url: "$next_database_url"
3265
echo next_index: "$next_index"
3366

34-
docker compose exec --env DATABASE_URL="$next_database_url" phpfpm bin/console doctrine:migrations:migrate --no-interaction
35-
# @todo Fetch data
36-
# docker compose exec --env DATABASE_URL="$next_database_url" phpfpm bin/console organisation:fetch:data
67+
compose exec --env DATABASE_URL="$next_database_url" phpfpm bin/console doctrine:migrations:migrate --no-interaction
68+
compose exec --env DATABASE_URL="$next_database_url" phpfpm bin/console --no-debug organisation:fetch:data --max="$max" --page-size="$page_size" -vvv
3769

3870
echo "DATABASE_URL='$next_database_url'" | tee >| .env.local.database
3971

4072
# Re-up to read in new database URL.
41-
docker compose up --detach
73+
compose up --detach
4274

4375
echo 'SUCCESS!'

bin/fetch-data.config.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Database URLs
2+
# database_urls=(
3+
# )
4+
5+
# Optional compose script path
6+
# compose_script=
7+
8+
# max=10
9+
# page_size=5

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"minimum-stability": "stable",
77
"prefer-stable": true,
88
"require": {
9-
"php": ">=8.2",
9+
"php": ">=8.1",
1010
"ext-ctype": "*",
1111
"ext-iconv": "*",
1212
"api-platform/core": "^3.2",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.override.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ services:
4747
jq:
4848
# https://github.com/jqlang/jq/pkgs/container/jq
4949
image: ghcr.io/jqlang/jq:1.7.1
50+
profiles:
51+
- dev

docker-compose.server.override.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
version: "3"
2-
31
services:
42
nginx:
53
# Give a different name since it is to be called from another container,
64
# which may already have a nginx container.
7-
container_name: organisation_api
5+
container_name: $COMPOSE_PROJECT_NAME-nginx
86

97
# Use production vhost config, which basically is just using the renamed php-fpm container below.
108
volumes:
@@ -17,4 +15,16 @@ services:
1715
phpfpm:
1816
# Give a different name since it is to be called from another container,
1917
# which may already have a phpfpm container.
20-
container_name: phpfpm-api
18+
container_name: $COMPOSE_PROJECT_NAME-phpfpm
19+
# https://docs.docker.com/compose/compose-file/05-services/#env_file/
20+
env_file:
21+
- path: ./.env
22+
- path: ./.env.local
23+
required: false
24+
- path: ./.env.local.database
25+
26+
jq:
27+
# https://github.com/jqlang/jq/pkgs/container/jq
28+
image: ghcr.io/jqlang/jq:1.7.1
29+
profiles:
30+
- dev

src/Service/FetchServiceFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Doctrine\ORM\EntityManagerInterface;
1111
use Psr\Log\LoggerInterface;
1212

13-
readonly class FetchServiceFactory
13+
class FetchServiceFactory
1414
{
1515
public function __construct(private EntityManagerInterface $entityManager, private SF1500Service $sf1500Service)
1616
{

src/State/BrugerFunktionerProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Exception\InvalidProviderRequestException;
88
use App\Repository\Model\FunktionRepository;
99

10-
readonly class BrugerFunktionerProvider implements ProviderInterface
10+
class BrugerFunktionerProvider implements ProviderInterface
1111
{
1212
public function __construct(private FunktionRepository $funktionRepository)
1313
{

src/State/BrugerLederFunktionerProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Exception\InvalidProviderRequestException;
88
use App\Repository\Model\FunktionRepository;
99

10-
readonly class BrugerLederFunktionerProvider implements ProviderInterface
10+
class BrugerLederFunktionerProvider implements ProviderInterface
1111
{
1212
public function __construct(private FunktionRepository $funktionRepository, private array $options)
1313
{

0 commit comments

Comments
 (0)