feat(M01-C): 建立MySQL异步任务基础

This commit is contained in:
Codex
2026-06-18 10:20:39 +08:00
parent a2d578f73b
commit 2b90d1f101
15 changed files with 609 additions and 30 deletions
+7
View File
@@ -11,6 +11,9 @@ $requiredFiles = @(
"backend/src/db/migration-runner.ts",
"backend/src/db/migrate-cli.ts",
"backend/src/db/legacy-read-repository.ts",
"backend/src/tasks/task-repository.ts",
"backend/src/tasks/outbox-repository.ts",
"backend/src/tasks/worker.ts",
"backend/src/routes/health.ts",
"backend/src/server.ts",
"backend/tests/backend-contract.test.mjs",
@@ -19,10 +22,14 @@ $requiredFiles = @(
"backend/tests/migration-runner.test.mjs",
"backend/tests/mysql-migration-roundtrip.test.mjs",
"backend/tests/legacy-read-repository.test.mjs",
"backend/tests/task-repository.test.mjs",
"scripts/dev/wsl/mysql-migration-roundtrip.sh",
"database/migrations/2026061601_m01b_core_schema.up.sql",
"database/migrations/2026061601_m01b_core_schema.down.sql",
"database/migrations/2026061601_m01b_core_schema.verify.sql",
"database/migrations/2026061802_m01c_async_tasks.up.sql",
"database/migrations/2026061802_m01c_async_tasks.down.sql",
"database/migrations/2026061802_m01c_async_tasks.verify.sql",
"database/seeds/2026061601_m01b_minimal_seed.sql",
"deploy/pm2/ecosystem.config.cjs"
)
+5 -5
View File
@@ -33,7 +33,7 @@ fi
mysql --batch --skip-column-names -e 'SELECT CURRENT_USER()' >/dev/null
run_id="$(date -u +%Y%m%d%H%M%S)_$$_$(openssl rand -hex 3)"
database="qipai_m01b_test_${run_id}"
database="qipai_m01c_test_${run_id}"
username="qmb_$$_$(openssl rand -hex 4)"
password="$(openssl rand -hex 24)"
created=0
@@ -63,7 +63,7 @@ if [[ "${1:-}" == "--force-failure" ]]; then
fi
if [[ "${1:-}" == "--cleanup-probe" ]]; then
before_database_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME LIKE 'qipai_m01b_test_%'")"
before_database_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME LIKE 'qipai_m01c_test_%'")"
before_user_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM mysql.user WHERE User LIKE 'qmb_%' AND Host = '127.0.0.1'")"
set +e
bash "${BASH_SOURCE[0]}" --force-failure
@@ -73,7 +73,7 @@ if [[ "${1:-}" == "--cleanup-probe" ]]; then
echo "FAIL: cleanup probe did not produce the expected interrupted status." >&2
exit 1
}
after_database_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME LIKE 'qipai_m01b_test_%'")"
after_database_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME LIKE 'qipai_m01c_test_%'")"
after_user_count="$(mysql --batch --skip-column-names -e "SELECT COUNT(*) FROM mysql.user WHERE User LIKE 'qmb_%' AND Host = '127.0.0.1'")"
if [[ "${before_database_count}" != "${after_database_count}" || "${before_user_count}" != "${after_user_count}" ]]; then
echo "FAIL: temporary MySQL resources survived an interrupted test." >&2
@@ -93,6 +93,6 @@ export QIPAI_MYSQL_USER="${username}"
export QIPAI_MYSQL_PASSWORD="${password}"
export QIPAI_MYSQL_CONNECTION_LIMIT=2
echo "INFO: MySQL ${mysql_version}; running M01-B migration roundtrip in a temporary database."
echo "INFO: MySQL ${mysql_version}; running M01-B/M01-C migration roundtrip in a temporary database."
npm --prefix backend run test:mysql:migration
echo "PASS: M01-B live MySQL migration roundtrip completed."
echo "PASS: M01-B/M01-C live MySQL migration roundtrip completed."