chore: simplify vars
Some checks failed
migrate-devel / migrate-devel (push) Failing after 1m36s

This commit is contained in:
Orion Kindel 2023-06-22 13:41:49 -05:00
parent 5da43ddf0f
commit 0d639e8a9d
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
4 changed files with 36 additions and 15 deletions

View File

@ -1,12 +1,8 @@
name: 'migrate'
on: { push: { branches: ['main'] } }
name: 'migrate-devel'
on: {push: {branches: ['main']}}
jobs:
devel:
name: 'migrate devel'
env:
POSTGRES_ROOT_CONNECTION_URL: '${{ secrets.DEVEL_POSTGRES_ROOT_CONNECTION_URL }}'
POSTGRES_CONNECTION_URL: '${{ secrets.DEVEL_POSTGRES_CONNECTION_URL }}'
migrate-devel:
steps:
- uses: 'actions/checkout@v3'
- name: 'install postgres'
@ -16,4 +12,10 @@ jobs:
apt-get install -y curl ca-certificates gnupg postgresql-common
YES=y sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
apt-get install -y postgresql-15
- run: 'echo "FOO=bar" > .env && ./scripts/migrate.sh'
- name: 'install postgres'
run: |
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh
- run: './scripts/migrate.sh'
env:
POSTGRES_URI: '${{ secrets.POSTGRES_DEVEL_URI }}'

View File

@ -0,0 +1,17 @@
name: 'migrate-devel'
on: {push: {branches: ['main']}}
jobs:
migrate-devel:
env:
POSTGRES_URI: '${{ secrets.devel_postgres_uri }}'
steps:
- uses: 'actions/checkout@v3'
- name: 'install postgres'
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
apt-get install -y curl ca-certificates gnupg postgresql-common
YES=y sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
apt-get install -y postgresql-15
- run: './scripts/migrate.sh'

View File

@ -2,4 +2,6 @@
file=${1:-./.env}
while read line; do export "$line"; done < "$file"
if [ -f "$file" ]; then
while read line; do export "$line"; done < "$file"
fi

View File

@ -12,21 +12,21 @@ fi
head=$(git show --format=format:%h -q)
get_dnim_database_count="copy (select count(*) from pg_database where datname = 'dnim') to stdout with null as '';"
dnim_database_count=$(psql "$POSTGRES_ROOT_CONNECTION_URL" -c "$get_dnim_database_count")
dnim_database_count=$(psql "$POSTGRES_URI/postgres" -c "$get_dnim_database_count")
if [[ "$dnim_database_count" = "0" ]]; then
echo "fresh database"
psql "$POSTGRES_ROOT_CONNECTION_URL" -c "create database dnim;"
ls ./schema/ | xargs -I{} psql --quiet "$POSTGRES_CONNECTION_URL" --file=./schema/{} 1>/dev/null
psql "$POSTGRES_URI/postgres" -c "create database dnim;"
ls ./schema/ | xargs -I{} psql --quiet "$POSTGRES_URI/dnim" --file=./schema/{} 1>/dev/null
last_revision='empty'
script=''
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_CONNECTION_URL" -c "$get_last_revision")
last_revision=$(psql "$POSTGRES_URI/dnim" -c "$get_last_revision")
script=$(./scripts/diff.sh "$last_revision")
if [[ "$1" = "--greenlight" ]]; then
psql "$POSTGRES_CONNECTION_URL" -c "$script"
psql "$POSTGRES_URI/dnim" -c "$script"
else
to_review="tmp/migrate_${last_revision}_to_${head}.sql"
echo "$script" > "$to_review"
@ -37,5 +37,5 @@ else
fi
insert_migration="insert into migration (from_revision, to_revision, script) values ('$last_revision', '$head', \$migration\$$script\$migration\$);"
psql "$POSTGRES_CONNECTION_URL" -c "$insert_migration"
psql "$POSTGRES_URI/dnim" -c "$insert_migration"
echo "inserted migration"