Skip to content

Commit e723688

Browse files
authored
Hotfix 0.8.5 (#3824)
* fix(cli): correctly handle `.env` files again * feat(ci): add functionality tests for sqlx-cli (MySQL) * feat(ci): add functionality tests for sqlx-cli (Postgres) * feat(ci): add functionality tests for sqlx-cli (SQLite) * chore: prepare 0.8.5 release * feat(ci): run `test-attr` tests twice to catch #3825 * fix: correct bugs in MySQL implementation of `#[sqlx::test]`
1 parent f908403 commit e723688

File tree

11 files changed

+435
-58
lines changed

11 files changed

+435
-58
lines changed

.github/workflows/sqlx-cli.yml

+231-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
--manifest-path sqlx-cli/Cargo.toml
3434
--target-dir target/beta/
3535
36-
test:
37-
name: Test
36+
integration-test:
37+
name: Integration Test
3838
runs-on: ${{ matrix.os }}
3939

4040
strategy:
@@ -57,6 +57,235 @@ jobs:
5757

5858
- run: cargo test --manifest-path sqlx-cli/Cargo.toml
5959

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+
60289
build:
61290
name: Build
62291
runs-on: ${{ matrix.os }}

0 commit comments

Comments
 (0)