-
Notifications
You must be signed in to change notification settings - Fork 75
95 lines (80 loc) · 3.38 KB
/
migration-sql.yml
File metadata and controls
95 lines (80 loc) · 3.38 KB
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
name: Alembic consistency check
on:
pull_request_target:
branches: [master]
jobs:
check-alembic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Get list of created migrations
id: get-changed-files
uses: ThiefMaster/changed-files-action@json-output
with:
repo-token: ${{ github.token }}
pattern: '^newdle/migrations/versions/.+\.py$'
- name: Check if any migrations changed
id: migrations-changed
run: |
echo ::set-output name=changed::${{ steps.get-changed-files.outputs.files_created != '[]' || steps.get-changed-files.outputs.files_updated != '[]' || steps.get-changed-files.outputs.files_deleted != '[]' }}
- name: Setup venv and config file
if: steps.migrations-changed.outputs.changed == 'true'
run: |
make config
make env
pip install -q -e '.[dev]'
- name: Activate virtualenv for later steps
if: steps.migrations-changed.outputs.changed == 'true'
run: |
echo "VIRTUAL_ENV=$(pwd)/.venv" >> $GITHUB_ENV
echo "$(pwd)/.venv/bin" >> $GITHUB_PATH
- name: Check history consistency
if: steps.migrations-changed.outputs.changed == 'true'
run: python ./ci/check_history_consistency.py
- name: Print changed migrations
if: steps.migrations-changed.outputs.changed == 'true'
id: get-comment-body
run: |
first_migration=$(jq -r '.[0] // empty' ~/files_created.json)
latest_migration=$(jq -r '.[-1] // empty' ~/files_created.json)
sql_command=$(./ci/print_revision_sql.sh $first_migration $latest_migration)
if [ ! -z "$sql_command" ] ; then
echo ::set-output name=body::$sql_command
fi
- name: Find previous comment
uses: peter-evans/find-comment@v1
id: find-comment
with:
issue-number: ${{ github.event.number }}
body-includes: This PR contains database changes.
comment-author: github-actions[bot]
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
if: steps.get-comment-body.outputs.body
with:
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
This PR contains database changes. Before merging it, make sure to apply the migration in production:
```sql
${{ steps.get-comment-body.outputs.body }}
```
When reviewing the PR, make sure that the changes will not break the previously deployed
version, i.e. any new column needs to have a `server_default` or be nullable.
- name: Delete comment
uses: peter-evans/create-or-update-comment@v1
if: steps.find-comment.outputs.comment-id && !steps.get-comment-body.outputs.body
with:
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
~~This PR contains database changes.~~