Skip to content

Commit bcd5fbc

Browse files
committed
Allow executing extra init scripts on initial migration
1 parent adfb39a commit bcd5fbc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ To apply the migrations, both as part as the initial setup and subsequently to k
7979
- ./pg_service.conf:/tmp/pg_service.conf:ro
8080
```
8181

82+
# Extra initialization
83+
84+
You can mount additional scripts to perform initial DB setup to `/tmp/extra-init.d`. These scripts will only be executed after the initial DB migration (i.e. if `alembic current` was empty).
85+
8286
# DB Schema overview
8387

8488
![er-diagram](er-diagram.png)

run-migrations.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,21 @@ until psql service=$PGSERVICE -c "select 1" > /dev/null 2>&1; do
55
sleep 1
66
done
77

8+
current_version=$(alembic current)
9+
echo "Current version: ${current_version}"
10+
11+
812
alembic upgrade ${ALEMBIC_VERSION}
13+
14+
if [ -z "$current_version" ] && [ -d "/tmp/extra-init.d" ]; then
15+
echo "Executing scripts in /tmp/extra-init.d..."
16+
for script in /tmp/extra-init.d/*; do
17+
if [ -f "$script" ] && [ -x "$script" ]; then
18+
echo "Running $script..."
19+
"$script"
20+
elif [ -f "$script" ]; then
21+
echo "Running $script with sh..."
22+
sh "$script"
23+
fi
24+
done
25+
fi

0 commit comments

Comments
 (0)