-
-
Notifications
You must be signed in to change notification settings - Fork 104
260 lines (226 loc) · 10.2 KB
/
test.yml
File metadata and controls
260 lines (226 loc) · 10.2 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: test
on:
pull_request:
push:
branches:
- main
- develop
jobs:
test-postgres:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: qui
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d qui"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Run tests (Postgres integration)
env:
QUI_TEST_POSTGRES_DSN: postgres://postgres:postgres@localhost:5432/qui?sslmode=disable
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
go test -v -timeout 20m ./internal/database -run TestOpenPostgres
else
go test -race -v -timeout 20m ./internal/database -run TestOpenPostgres
fi
migration-parity:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
PG_ADMIN_DSN: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
PG_MIGRATION_DSN: postgres://postgres:postgres@localhost:5432/qui_migration_ci?sslmode=disable
MIGRATION_TMPDIR: .tmp/migration-ci
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Install sqlite3 + psql clients
run: |
sudo apt-get update
sudo apt-get install -y sqlite3 postgresql-client
- name: Build SQLite fixture (current schema)
run: |
set -euo pipefail
rm -rf "$MIGRATION_TMPDIR"
mkdir -p "$MIGRATION_TMPDIR"
go run ./cmd/qui generate-config --config-dir "$MIGRATION_TMPDIR"
go run ./cmd/qui create-user \
--config-dir "$MIGRATION_TMPDIR" \
--data-dir "$MIGRATION_TMPDIR" \
--username ci \
--password ci-password-123
SQLITE_DB="$MIGRATION_TMPDIR/qui.db"
test -f "$SQLITE_DB"
# Seed one orphan feed item intentionally; migration should filter it.
sqlite3 "$SQLITE_DB" <<'SQL'
PRAGMA foreign_keys = OFF;
INSERT OR IGNORE INTO cross_seed_feed_items (
guid, indexer_id, title, first_seen_at, last_seen_at, last_status, last_run_id, info_hash
) VALUES (
'ci-orphan-guid', 999999, 'orphan row', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'pending', NULL, NULL
);
SQL
- name: Apply SQLite -> Postgres migration
run: |
set -euo pipefail
psql -X "$PG_ADMIN_DSN" -v ON_ERROR_STOP=1 \
-c "DROP DATABASE IF EXISTS qui_migration_ci;" \
-c "CREATE DATABASE qui_migration_ci;"
go run ./cmd/qui db migrate \
--from-sqlite "$MIGRATION_TMPDIR/qui.db" \
--to-postgres "$PG_MIGRATION_DSN" \
--apply \
| tee "$MIGRATION_TMPDIR/migrate.log"
- name: Validate schema parity + expected filtered rows
run: |
set -euo pipefail
SQLITE_DB="$MIGRATION_TMPDIR/qui.db"
DIAG_TSV="$MIGRATION_TMPDIR/migration-counts.tsv"
DIAG_SCHEMA="$MIGRATION_TMPDIR/migration-schema.tsv"
DIAG_CROSSSEED="$MIGRATION_TMPDIR/cross-seed-diagnostics.txt"
echo -e "table\tsqlite\tpostgres\tnote" > "$DIAG_TSV"
echo -e "kind\tname\tsqlite\tpostgres\tnote" > "$DIAG_SCHEMA"
fail=0
declare -A SQLITE_TABLES=()
while IFS= read -r table; do
[ -n "$table" ] && SQLITE_TABLES["$table"]=1
done < <(sqlite3 "$SQLITE_DB" "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != 'migrations' ORDER BY name;")
declare -A PG_TABLES=()
while IFS= read -r table; do
[ -n "$table" ] && PG_TABLES["$table"]=1
done < <(psql -X "$PG_MIGRATION_DSN" -Atc "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' AND table_name != 'migrations' ORDER BY table_name;")
while IFS= read -r table; do
[ -z "$table" ] && continue
if [ -z "${PG_TABLES[$table]:-}" ]; then
echo -e "table\t$table\tpresent\tmissing\tmissing_postgres_table" | tee -a "$DIAG_SCHEMA"
fail=1
continue
fi
echo -e "table\t$table\tpresent\tpresent\tok" >> "$DIAG_SCHEMA"
declare -A SQLITE_COLUMNS=()
while IFS='|' read -r _ column _; do
[ -n "$column" ] && SQLITE_COLUMNS["$column"]=1
done < <(sqlite3 "$SQLITE_DB" "PRAGMA table_info(\"$table\");")
declare -A PG_COLUMNS=()
while IFS= read -r column; do
[ -n "$column" ] && PG_COLUMNS["$column"]=1
done < <(psql -X "$PG_MIGRATION_DSN" -Atc "SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '$table' ORDER BY ordinal_position;")
while IFS='|' read -r _ column _; do
[ -z "$column" ] && continue
if [ -z "${PG_COLUMNS[$column]:-}" ]; then
echo -e "column\t$table.$column\tpresent\tmissing\tmissing_postgres_column" | tee -a "$DIAG_SCHEMA"
fail=1
continue
fi
echo -e "column\t$table.$column\tpresent\tpresent\tok" >> "$DIAG_SCHEMA"
done < <(sqlite3 "$SQLITE_DB" "PRAGMA table_info(\"$table\");")
while IFS= read -r column; do
[ -z "$column" ] && continue
if [ -z "${SQLITE_COLUMNS[$column]:-}" ]; then
echo -e "column\t$table.$column\tmissing\tpresent\textra_postgres_column" | tee -a "$DIAG_SCHEMA"
fail=1
fi
done < <(psql -X "$PG_MIGRATION_DSN" -Atc "SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = '$table' ORDER BY ordinal_position;")
done < <(sqlite3 "$SQLITE_DB" "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != 'migrations' ORDER BY name;")
while IFS= read -r table; do
[ -z "$table" ] && continue
if [ -z "${SQLITE_TABLES[$table]:-}" ]; then
echo -e "table\t$table\tmissing\tpresent\textra_postgres_table" | tee -a "$DIAG_SCHEMA"
fail=1
fi
done < <(psql -X "$PG_MIGRATION_DSN" -Atc "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' AND table_name != 'migrations' ORDER BY table_name;")
while IFS= read -r table; do
[ -z "$table" ] && continue
sqlite_count="$(sqlite3 "$SQLITE_DB" "SELECT COUNT(*) FROM \"$table\";")"
if [ -z "${PG_TABLES[$table]:-}" ]; then
echo -e "$table\t$sqlite_count\tMISSING\tmissing_postgres_table" | tee -a "$DIAG_TSV"
fail=1
continue
fi
pg_count="$(psql -X "$PG_MIGRATION_DSN" -Atc "SELECT COUNT(*) FROM public.\"$table\";")"
note="ok"
if [ "$table" = "cross_seed_feed_items" ]; then
expected_count="$(sqlite3 "$SQLITE_DB" "
SELECT COUNT(*)
FROM cross_seed_feed_items f
WHERE EXISTS (SELECT 1 FROM torznab_indexers i WHERE i.id = f.indexer_id)
AND (f.last_run_id IS NULL OR EXISTS (SELECT 1 FROM cross_seed_runs r WHERE r.id = f.last_run_id));
")"
orphan_indexer_count="$(sqlite3 "$SQLITE_DB" "
SELECT COUNT(*)
FROM cross_seed_feed_items f
LEFT JOIN torznab_indexers i ON i.id = f.indexer_id
WHERE i.id IS NULL;
")"
orphan_run_count="$(sqlite3 "$SQLITE_DB" "
SELECT COUNT(*)
FROM cross_seed_feed_items f
LEFT JOIN cross_seed_runs r ON r.id = f.last_run_id
WHERE f.last_run_id IS NOT NULL AND r.id IS NULL;
")"
{
echo "cross_seed_feed_items sqlite_count=$sqlite_count"
echo "cross_seed_feed_items postgres_count=$pg_count"
echo "cross_seed_feed_items expected_count=$expected_count"
echo "cross_seed_feed_items orphan_indexer_count=$orphan_indexer_count"
echo "cross_seed_feed_items orphan_run_count=$orphan_run_count"
} | tee "$DIAG_CROSSSEED"
if [ "$pg_count" != "$expected_count" ]; then
note="unexpected_filtered_count expected=$expected_count"
fail=1
else
note="filtered_fk_orphans expected=$expected_count"
fi
elif [ "$sqlite_count" != "$pg_count" ]; then
note="mismatch"
fail=1
fi
echo -e "$table\t$sqlite_count\t$pg_count\t$note" | tee -a "$DIAG_TSV"
done < <(sqlite3 "$SQLITE_DB" "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != 'migrations' ORDER BY name;")
if [ "$fail" -ne 0 ]; then
echo "Migration parity check failed. See $DIAG_TSV and $DIAG_CROSSSEED."
exit 1
fi
- name: Upload migration diagnostics
if: failure()
uses: actions/upload-artifact@v7
with:
name: migration-parity-diagnostics
path: |
.tmp/migration-ci/migrate.log
.tmp/migration-ci/migration-counts.tsv
.tmp/migration-ci/migration-schema.tsv
.tmp/migration-ci/cross-seed-diagnostics.txt