fix: support manually fiddling with migrations
This commit is contained in:
parent
b3de72daf2
commit
5f310779b3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.env
|
.env
|
||||||
data
|
data
|
||||||
tmp
|
tmp
|
||||||
|
migrations
|
||||||
|
@ -1,25 +1,38 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
set -ex
|
set -e
|
||||||
|
|
||||||
source ./scripts/env.sh ./.env.schema
|
source ./scripts/env.sh ./.env.schema
|
||||||
|
|
||||||
rev=${1:-}
|
rev=$(echo "$1" | xargs)
|
||||||
|
head=$(git show --format=format:%h -q | xargs)
|
||||||
|
migration="./migrations/${rev}_to_${head}.sql"
|
||||||
|
|
||||||
head_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/dnim
|
head_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/dnim
|
||||||
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/dnim
|
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/dnim
|
||||||
|
|
||||||
if [[ -z "$rev" ]]; then
|
if [[ -z "$rev" ]]; then
|
||||||
echo "revision to diff is required";
|
echo "revision to diff is required" 1>&2;
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker compose up -d
|
docker compose up -d 1>&2
|
||||||
|
|
||||||
./scripts/build.sh $rev
|
rm -r ./migrations || true
|
||||||
./scripts/build.sh HEAD
|
git fetch --all 1>&2
|
||||||
|
git restore ./migrations --source origin/manual_migrations 1>&2
|
||||||
|
|
||||||
echo "migrate from $rev => HEAD" 1>&2
|
if [[ ! -f "$migration" ]]; then
|
||||||
migra --unsafe $base_url $head_url || echo "migra exited with code $?. this is /probably/ fine" 1>&2
|
./scripts/build.sh "$rev"
|
||||||
|
./scripts/build.sh HEAD
|
||||||
|
|
||||||
|
echo "migrate from $rev => HEAD" 1>&2
|
||||||
|
|
||||||
docker compose down
|
migra --unsafe $base_url $head_url \
|
||||||
|
|| echo "migra exited with code $?. this is /probably/ fine" 1>&2 \
|
||||||
|
> "$migration"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$migration"
|
||||||
|
|
||||||
|
docker compose down 1>&2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
set -xe
|
set -e
|
||||||
|
|
||||||
source ./scripts/env.sh ./.env
|
source ./scripts/env.sh ./.env
|
||||||
|
|
||||||
@ -23,16 +23,13 @@ if [[ "$dnim_database_count" = "0" ]]; then
|
|||||||
else
|
else
|
||||||
get_last_revision="copy (select to_revision from migration order by performed_on desc limit 1) to stdout with null as '';"
|
get_last_revision="copy (select to_revision from migration order by performed_on desc limit 1) to stdout with null as '';"
|
||||||
last_revision=$(psql "$POSTGRES_URI/dnim" -c "$get_last_revision")
|
last_revision=$(psql "$POSTGRES_URI/dnim" -c "$get_last_revision")
|
||||||
script=$(./scripts/diff.sh "$last_revision")
|
migration_file=$(./scripts/diff.sh "$last_revision")
|
||||||
|
|
||||||
if [[ "$1" = "--greenlight" ]]; then
|
if [[ "$1" = "--greenlight" ]]; then
|
||||||
psql "$POSTGRES_URI/dnim" -c "$script"
|
psql "$POSTGRES_URI/dnim" -f "$migration_file"
|
||||||
else
|
else
|
||||||
mkdir -p tmp
|
echo "migration available at $migration_file"
|
||||||
to_review="tmp/migrate_${last_revision}_to_${head}.sql"
|
echo "review and rerun with --greenlight to apply"
|
||||||
echo "$script" > "$to_review"
|
|
||||||
echo "script written to $to_review"
|
|
||||||
echo "review and rerun with --greenlight to apply migration"
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user