-
Notifications
You must be signed in to change notification settings - Fork 7
93 lines (88 loc) · 3.44 KB
/
test_migration.yml
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
name: Migration Test
on:
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
jobs:
test_migrations:
runs-on: ubuntu-latest
services:
auto_mysql:
image: mysql:9
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: super_secret_passw0rd
MYSQL_DATABASE: campus_db
manual_mysql:
image: mysql:9
ports:
- 3300:3306
env:
MYSQL_ROOT_PASSWORD: super_secret_passw0rd
MYSQL_DATABASE: campus_db
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
cache-dependency-path: |
server/go.sum
- name: run manual migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "false"
DB_NAME: campus_db
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- name: run auto migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "true"
DB_NAME: campus_db
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3300)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- uses: ariga/setup-atlas@master
- name: export diff the migrations
id: diff_migrations
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) &&
echo "local_to_auto<<$EOF" >> $GITHUB_OUTPUT &&
atlas schema diff --from "mysql://root:super_secret_passw0rd@localhost:3300/campus_db?charset=utf8mb4&parseTime=True&loc=Local" --to "mysql://root:super_secret_passw0rd@localhost:3306/campus_db?charset=utf8mb4&parseTime=True&loc=Local" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
echo "$EOF" >> $GITHUB_OUTPUT
echo "auto_to_local<<$EOF" >> $GITHUB_OUTPUT &&
atlas schema diff --from "mysql://root:super_secret_passw0rd@localhost:3306/campus_db?charset=utf8mb4&parseTime=True&loc=Local" --to "mysql://root:super_secret_passw0rd@localhost:3300/campus_db?charset=utf8mb4&parseTime=True&loc=Local" --format '{{ sql . " " }}' >> $GITHUB_OUTPUT &&
echo "$EOF" >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: "${{ github.event.number }}"
body-includes: Found the following differences in the sql schema
comment-author: github-actions[bot]
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: "${{ github.event.number }}"
comment-id: "${{ steps.fc.outputs.comment-id }}"
body: |
:eyes: Found the following differences in the sql schema:
<details>
<summary>Needed get from <b>local</b> to <b>auto</b> migration state</summary>
```sql
${{ steps.diff_migrations.outputs.local_to_auto }}
```
</details>
<details>
<summary>Needed from <b>auto</b> to <b>local</b> migration state</summary>
```sql
${{ steps.diff_migrations.outputs.auto_to_local }}
```
</details>
edit-mode: replace