33
33
--manifest-path sqlx-cli/Cargo.toml
34
34
--target-dir target/beta/
35
35
36
- test :
37
- name : Test
36
+ integration- test :
37
+ name : Integration Test
38
38
runs-on : ${{ matrix.os }}
39
39
40
40
strategy :
@@ -57,6 +57,235 @@ jobs:
57
57
58
58
- run : cargo test --manifest-path sqlx-cli/Cargo.toml
59
59
60
+ test-mysql :
61
+ name : Functional Test (MySQL)
62
+ runs-on : ubuntu-latest
63
+ # Deliberately not using `tests/docker-compose.yml` because that sets up the database automatically.
64
+ services :
65
+ mysql :
66
+ image : mysql:8
67
+ ports :
68
+ - 3306:3306
69
+ env :
70
+ MYSQL_ROOT_PASSWORD : password
71
+ env :
72
+ BASE_URL : mysql://root:password@localhost
73
+
74
+ steps :
75
+ - uses : actions/checkout@v4
76
+
77
+ - name : Setup Rust
78
+ run : rustup show active-toolchain || rustup toolchain install
79
+
80
+ - uses : Swatinem/rust-cache@v2
81
+
82
+ - name : Install SQLx-CLI
83
+ run :
84
+ cargo install --locked --debug --path sqlx-cli
85
+
86
+ - name : Basic Test
87
+ env :
88
+ DATABASE_URL : ${{ env.BASE_URL }}/test1
89
+ run : |
90
+ sqlx db setup --source=tests/mysql/migrations
91
+
92
+ sqlx mig info --source=tests/mysql/migrations
93
+
94
+ sqlx db drop -y
95
+
96
+ - name : Test .env
97
+ run : |
98
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test2" > .env
99
+
100
+ sqlx db setup --source=tests/mysql/migrations
101
+
102
+ sqlx mig info --source=tests/mysql/migrations
103
+
104
+ sqlx db drop -y
105
+
106
+ - name : Test --no-dotenv
107
+ run : |
108
+ # Allow subcommands to fail
109
+ set +e
110
+
111
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test3" > .env
112
+
113
+ ERROR=$(sqlx db setup --no-dotenv --source=tests/mysql/migrations)
114
+
115
+ if [[ "$ERROR" == *"--database-url"* ]]; then
116
+ exit 0
117
+ else
118
+ echo "Unexpected error from sqlx-cli: $ERROR"
119
+ exit 1
120
+ fi
121
+
122
+ - name : Test Reversible Migrations
123
+ env :
124
+ DATABASE_URL : ${{ env.BASE_URL }}/test4
125
+ run : |
126
+ sqlx db setup --source=tests/mysql/migrations_reversible
127
+
128
+ INFO_BEFORE=$(sqlx mig info --source=tests/mysql/migrations_reversible)
129
+
130
+ sqlx mig revert --target-version=0 --source=tests/mysql/migrations_reversible
131
+
132
+ INFO_AFTER=$(sqlx mig info --source=tests/mysql/migrations_reversible)
133
+
134
+ if [[ "$INFO_BEFORE" == "$INFO_AFTER" ]]; then
135
+ echo "Error: migration info is identical before and after migrating: $INFO_BEFORE"
136
+ exit 1
137
+ fi
138
+
139
+ test-postgres :
140
+ name : Functional Test (PostgreSQL)
141
+ runs-on : ubuntu-latest
142
+ # Deliberately not using `tests/docker-compose.yml` because that sets up the database automatically.
143
+ services :
144
+ mysql :
145
+ image : postgres:17
146
+ ports :
147
+ - 5432:5432
148
+ env :
149
+ POSTGRES_PASSWORD : password
150
+ env :
151
+ BASE_URL : postgres://postgres:password@localhost
152
+
153
+ steps :
154
+ - uses : actions/checkout@v4
155
+
156
+ - name : Setup Rust
157
+ run : rustup show active-toolchain || rustup toolchain install
158
+
159
+ - uses : Swatinem/rust-cache@v2
160
+
161
+ - name : Install SQLx-CLI
162
+ run :
163
+ cargo install --locked --debug --path sqlx-cli
164
+
165
+ - name : Basic Test
166
+ env :
167
+ DATABASE_URL : ${{ env.BASE_URL }}/test1
168
+ run : |
169
+ sqlx db setup --source=tests/postgres/migrations
170
+
171
+ sqlx mig info --source=tests/postgres/migrations
172
+
173
+ sqlx db drop -y
174
+
175
+ - name : Test .env
176
+ run : |
177
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test2" > .env
178
+
179
+ sqlx db setup --source=tests/postgres/migrations
180
+
181
+ sqlx mig info --source=tests/postgres/migrations
182
+
183
+ sqlx db drop -y
184
+
185
+ - name : Test --no-dotenv
186
+ run : |
187
+ # Allow subcommands to fail
188
+ set +e
189
+
190
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test3" > .env
191
+
192
+ ERROR=$(sqlx db setup --no-dotenv --source=tests/postgres/migrations)
193
+
194
+ if [[ "$ERROR" == *"--database-url"* ]]; then
195
+ exit 0
196
+ else
197
+ echo "Unexpected error from sqlx-cli: $ERROR"
198
+ exit 1
199
+ fi
200
+
201
+ - name : Test Reversible Migrations
202
+ env :
203
+ DATABASE_URL : ${{ env.BASE_URL }}/test4
204
+ run : |
205
+ sqlx db setup --source=tests/postgres/migrations_reversible
206
+
207
+ INFO_BEFORE=$(sqlx mig info --source=tests/postgres/migrations_reversible)
208
+
209
+ sqlx mig revert --target-version=0 --source=tests/postgres/migrations_reversible
210
+
211
+ INFO_AFTER=$(sqlx mig info --source=tests/postgres/migrations_reversible)
212
+
213
+ if [[ "$INFO_BEFORE" == "$INFO_AFTER" ]]; then
214
+ echo "Error: migration info is identical before and after migrating: $INFO_BEFORE"
215
+ exit 1
216
+ fi
217
+
218
+ test-sqlite :
219
+ name : Functional Test (SQLite)
220
+ runs-on : ubuntu-latest
221
+ env :
222
+ BASE_URL : sqlite://.
223
+
224
+ steps :
225
+ - uses : actions/checkout@v4
226
+
227
+ - name : Setup Rust
228
+ run : rustup show active-toolchain || rustup toolchain install
229
+
230
+ - uses : Swatinem/rust-cache@v2
231
+
232
+ - name : Install SQLx-CLI
233
+ run :
234
+ cargo install --locked --debug --path sqlx-cli
235
+
236
+ - name : Basic Test
237
+ env :
238
+ DATABASE_URL : ${{ env.BASE_URL }}/test1
239
+ run : |
240
+ sqlx db setup --source=tests/sqlite/migrations
241
+
242
+ sqlx mig info --source=tests/sqlite/migrations
243
+
244
+ sqlx db drop -y
245
+
246
+ - name : Test .env
247
+ run : |
248
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test2" > .env
249
+
250
+ sqlx db setup --source=tests/sqlite/migrations
251
+
252
+ sqlx mig info --source=tests/sqlite/migrations
253
+
254
+ sqlx db drop -y
255
+
256
+ - name : Test --no-dotenv
257
+ run : |
258
+ # Allow subcommands to fail
259
+ set +e
260
+
261
+ echo "DATABASE_URL=${{ env.BASE_URL }}/test3" > .env
262
+
263
+ ERROR=$(sqlx db setup --no-dotenv --source=tests/sqlite/migrations)
264
+
265
+ if [[ "$ERROR" == *"--database-url"* ]]; then
266
+ exit 0
267
+ else
268
+ echo "Unexpected error from sqlx-cli: $ERROR"
269
+ exit 1
270
+ fi
271
+
272
+ - name : Test Reversible Migrations
273
+ env :
274
+ DATABASE_URL : ${{ env.BASE_URL }}/test4
275
+ run : |
276
+ sqlx db setup --source=tests/sqlite/migrations_reversible
277
+
278
+ INFO_BEFORE=$(sqlx mig info --source=tests/sqlite/migrations_reversible)
279
+
280
+ sqlx mig revert --target-version=0 --source=tests/sqlite/migrations_reversible
281
+
282
+ INFO_AFTER=$(sqlx mig info --source=tests/sqlite/migrations_reversible)
283
+
284
+ if [[ "$INFO_BEFORE" == "$INFO_AFTER" ]]; then
285
+ echo "Error: migration info is identical before and after migrating: $INFO_BEFORE"
286
+ exit 1
287
+ fi
288
+
60
289
build :
61
290
name : Build
62
291
runs-on : ${{ matrix.os }}
0 commit comments