This commit is contained in:
parent
5da43ddf0f
commit
0d639e8a9d
@ -1,12 +1,8 @@
|
|||||||
name: 'migrate'
|
name: 'migrate-devel'
|
||||||
on: { push: { branches: ['main'] } }
|
on: {push: {branches: ['main']}}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
devel:
|
migrate-devel:
|
||||||
name: 'migrate devel'
|
|
||||||
env:
|
|
||||||
POSTGRES_ROOT_CONNECTION_URL: '${{ secrets.DEVEL_POSTGRES_ROOT_CONNECTION_URL }}'
|
|
||||||
POSTGRES_CONNECTION_URL: '${{ secrets.DEVEL_POSTGRES_CONNECTION_URL }}'
|
|
||||||
steps:
|
steps:
|
||||||
- uses: 'actions/checkout@v3'
|
- uses: 'actions/checkout@v3'
|
||||||
- name: 'install postgres'
|
- name: 'install postgres'
|
||||||
@ -16,4 +12,10 @@ jobs:
|
|||||||
apt-get install -y curl ca-certificates gnupg postgresql-common
|
apt-get install -y curl ca-certificates gnupg postgresql-common
|
||||||
YES=y sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
|
YES=y sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
|
||||||
apt-get install -y postgresql-15
|
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}
|
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)
|
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 '';"
|
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
|
if [[ "$dnim_database_count" = "0" ]]; then
|
||||||
echo "fresh database"
|
echo "fresh database"
|
||||||
psql "$POSTGRES_ROOT_CONNECTION_URL" -c "create database dnim;"
|
psql "$POSTGRES_URI/postgres" -c "create database dnim;"
|
||||||
ls ./schema/ | xargs -I{} psql --quiet "$POSTGRES_CONNECTION_URL" --file=./schema/{} 1>/dev/null
|
ls ./schema/ | xargs -I{} psql --quiet "$POSTGRES_URI/dnim" --file=./schema/{} 1>/dev/null
|
||||||
last_revision='empty'
|
last_revision='empty'
|
||||||
script=''
|
script=''
|
||||||
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_CONNECTION_URL" -c "$get_last_revision")
|
last_revision=$(psql "$POSTGRES_URI/dnim" -c "$get_last_revision")
|
||||||
script=$(./scripts/diff.sh "$last_revision")
|
script=$(./scripts/diff.sh "$last_revision")
|
||||||
|
|
||||||
if [[ "$1" = "--greenlight" ]]; then
|
if [[ "$1" = "--greenlight" ]]; then
|
||||||
psql "$POSTGRES_CONNECTION_URL" -c "$script"
|
psql "$POSTGRES_URI/dnim" -c "$script"
|
||||||
else
|
else
|
||||||
to_review="tmp/migrate_${last_revision}_to_${head}.sql"
|
to_review="tmp/migrate_${last_revision}_to_${head}.sql"
|
||||||
echo "$script" > "$to_review"
|
echo "$script" > "$to_review"
|
||||||
@ -37,5 +37,5 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
insert_migration="insert into migration (from_revision, to_revision, script) values ('$last_revision', '$head', \$migration\$$script\$migration\$);"
|
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"
|
echo "inserted migration"
|
||||||
|
Loading…
Reference in New Issue
Block a user