This commit is contained in:
parent
5da43ddf0f
commit
0d639e8a9d
@ -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 }}'
|
||||
|
17
.gitea/workflows/migrate-stage.yml
Normal file
17
.gitea/workflows/migrate-stage.yml
Normal 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'
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user