-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (130 loc) · 4.42 KB
/
db-changes-var1.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: DB Change Check var1 - K
on:
pull_request:
branches:
- main
jobs:
check-sql-schema-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check For Changes
id: changed-db-files
uses: tj-actions/changed-files@v44
with:
files: "app/**"
- name: Check Conditions
id: check-conditions
run: |
echo "DB_CHANGE=${{ steps.changed-db-files.outputs.any_changed }}" >> $GITHUB_ENV
run-alembic:
needs: check-sql-schema-changes
# if: ${{ needs.check-sql-schema-changes.DB_CHANGE == 'true' }}
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:14-3.4
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_HOST: localhost
POSTGRES_DRIVERNAME: postgresql
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Drop unwanted PostGIS extensions
run: |
psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS postgis_tiger_geocoder CASCADE;"
psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS postgis_topology CASCADE;"
psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS fuzzystrmatch CASCADE;"
env:
PGPASSWORD: postgres
- name: Checkout Main Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'main'
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Generate envs & set path
id: generate-envs
run: |
DATABASE_URL="postgresql://postgres:postgres@localhost:5432"
echo "DATABASE_URL=$DATABASE_URL" >> $GITHUB_ENV
echo "PYTHONPATH=$PYTHONPATH:$(pwd)" >> $GITHUB_ENV
- name: Install dependencies
id: install-dependencies
run: |
python -m pip install --upgrade pip
pip install -r app/requirements.txt
- name: Run alembic script autogen for Initial DB Setup
id: run-alembic-script-autogen
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
alembic -c alembic.ini revision --autogenerate -m "test_temp_db_001"
- name: Alembic Upgrade Head
id: run-alembic-upgrade-initial
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
alembic -c alembic.ini upgrade head
git branch
git status
git add .
git stash
- name: Checkout New Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run alembic script autogeneration
id: run-alembic-script-autogen-round-2
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
git branch
git stash pop
alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002"
- name: Upgrade alembic head with new revision
id: run-alembic-upgrade-new
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
alembic -c alembic.ini upgrade head
- name: Test DB is set up correctly
id: test-db-set-up
run: |
set -e # catch errors
python migrations/test_migration.py
# - name: Checkout new branch
# id: checkout-new-branch
# run: |
# git config --global user.email "github-actions[bot]@users.noreply.github.com"
# git config --global user.name "github-actions[bot]"
# git checkout -b ${{ env.BRANCH_NAME }}
# git push origin ${{ env.BRANCH_NAME }}
# - name: Add alembic script to new branch
# id: add-alembic-script-to-new-branch
# run: |
# git add .
# git commit -m "Add new Alembic migration"
# git push origin HEAD:${{ github.ref }}
# - name: Create PR
# id: create-pull-request
# uses: peter-evans/create-pull-request@v5
# with:
# branch: ${{ env.BRANCH_NAME }}
# base: main
# title: "BotPR: {{ env.BRANCH_NAME }}"
# author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"