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
|
||||
data
|
||||
tmp
|
||||
migrations
|
||||
|
@ -1,25 +1,38 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
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
|
||||
base_url=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5433/dnim
|
||||
|
||||
if [[ -z "$rev" ]]; then
|
||||
echo "revision to diff is required";
|
||||
echo "revision to diff is required" 1>&2;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
docker compose up -d
|
||||
docker compose up -d 1>&2
|
||||
|
||||
./scripts/build.sh $rev
|
||||
./scripts/build.sh HEAD
|
||||
rm -r ./migrations || true
|
||||
git fetch --all 1>&2
|
||||
git restore ./migrations --source origin/manual_migrations 1>&2
|
||||
|
||||
echo "migrate from $rev => HEAD" 1>&2
|
||||
migra --unsafe $base_url $head_url || echo "migra exited with code $?. this is /probably/ fine" 1>&2
|
||||
if [[ ! -f "$migration" ]]; then
|
||||
./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
|
||||
|
||||
set -xe
|
||||
set -e
|
||||
|
||||
source ./scripts/env.sh ./.env
|
||||
|
||||
@ -23,16 +23,13 @@ if [[ "$dnim_database_count" = "0" ]]; then
|
||||
else
|
||||
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")
|
||||
script=$(./scripts/diff.sh "$last_revision")
|
||||
migration_file=$(./scripts/diff.sh "$last_revision")
|
||||
|
||||
if [[ "$1" = "--greenlight" ]]; then
|
||||
psql "$POSTGRES_URI/dnim" -c "$script"
|
||||
psql "$POSTGRES_URI/dnim" -f "$migration_file"
|
||||
else
|
||||
mkdir -p tmp
|
||||
to_review="tmp/migrate_${last_revision}_to_${head}.sql"
|
||||
echo "$script" > "$to_review"
|
||||
echo "script written to $to_review"
|
||||
echo "review and rerun with --greenlight to apply migration"
|
||||
echo "migration available at $migration_file"
|
||||
echo "review and rerun with --greenlight to apply"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user