summaryrefslogtreecommitdiff
path: root/doc/developer-utils/create-alembic-migration.sh
blob: df7a29eb68f6e1c4712aa923452aa6723180d5df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

# Helper script to create an alembic migration file via Docker

if [ $# -lt 1 ]; then
    echo "Need to pass a name for your migration file" > /dev/stderr
    exit 1
fi

# Create a dummy container
WORKDIR="$(git rev-parse --show-toplevel)/server"
IMAGE=$(docker build -q "${WORKDIR}")
CONTAINER=$(docker run -d ${IMAGE} tail -f /dev/null)

# Create the migration script
docker exec -i \
    -e PYTHONPATH='/opt/app' \
    -e POSTGRES_HOST='x' \
    -e POSTGRES_USER='x' \
    -e POSTGRES_PASSWORD='x' \
    ${CONTAINER} alembic revision -m "$1"

# Copy the file over from the container
docker cp ${CONTAINER}:/opt/app/szurubooru/migrations/versions/ \
    "${WORKDIR}/szurubooru/migrations/"

# Destroy the dummy container
docker rm -f ${CONTAINER} > /dev/null