Skip to content

Commit e66ed20

Browse files
Merge pull request #49 from codeErrorSleep/release/260325
Release/260325
2 parents 65a68fd + 22af678 commit e66ed20

77 files changed

Lines changed: 12888 additions & 1462 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-22.04
11+
timeout-minutes: 40
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Bun
18+
uses: oven-sh/setup-bun@v2
19+
with:
20+
bun-version: latest
21+
22+
- name: Cache Bun dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
node_modules
27+
~/.bun/install/cache
28+
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-bun-
31+
32+
- name: Install frontend dependencies
33+
run: bun install --frozen-lockfile
34+
35+
- name: Setup Rust toolchain
36+
uses: dtolnay/rust-toolchain@stable
37+
38+
- name: Cache Rust build artifacts
39+
uses: Swatinem/rust-cache@v2
40+
with:
41+
workspaces: src-tauri -> src-tauri/target
42+
43+
- name: Run unit tests
44+
run: bun run test:unit
45+
46+
- name: Run service tests
47+
run: bun run test:service
48+
49+
- name: Run rust unit tests
50+
run: bun run test:rust:unit
51+
52+
- name: Run integration tests (MySQL + Postgres with testcontainers)
53+
run: IT_DB=all bun run test:integration
54+
55+
- name: Docker diagnostics on failure
56+
if: failure()
57+
run: |
58+
echo "==== docker ps -a ===="
59+
docker ps -a || true
60+
echo "==== recent mysql/postgres logs ===="
61+
for image in mysql:8.0 postgres:16-alpine; do
62+
for id in $(docker ps -aq --filter "ancestor=${image}"); do
63+
echo "--- logs for $id (${image}) ---"
64+
docker logs "$id" || true
65+
done
66+
done

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ reference
3333
# plan
3434
.trae/documents/
3535
.cursor/plans/
36+
37+
# skills
38+
.trae/skills/*
39+
40+
# example
41+
githubworkflowexample/*

CHANGELOG.md

Lines changed: 0 additions & 86 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ English | [简体中文](README_CN.md) | [日本語](README_JA.md)
3636
- Connect to PostgreSQL, MySQL, MariaDB (MySQL-compatible), TiDB (MySQL-compatible), SQLite, SQL Server, and ClickHouse (preview, currently read-only)
3737
- Write and run SQL with syntax highlighting, auto-completion, and one-click formatting
3838
- Browse query results in a data grid with filtering, sorting, pagination, and export
39+
- Import `.sql` files into MySQL/MariaDB/TiDB/PostgreSQL/SQLite/DuckDB/SQL Server with all-or-nothing rollback
3940
- Save and reuse frequently used SQL scripts with Saved Queries
4041
- Use the AI sidebar to draft SQL and explain queries (optional)
4142
- Access remote databases through SSH tunneling

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- 连接 PostgreSQL、MySQL、MariaDB(MySQL 兼容)、TiDB(MySQL 兼容)、SQLite、SQL Server 与 ClickHouse(预览版,当前只读)
3737
- 编写与执行 SQL:语法高亮、自动补全、一键格式化
3838
- 在数据网格中浏览结果,支持过滤、排序、分页与导出
39+
- 支持将 `.sql` 文件导入 MySQL/MariaDB/TiDB/PostgreSQL/SQLite/DuckDB/SQL Server,并在失败时全量回滚
3940
- 使用 Saved Queries 保存并复用常用 SQL 脚本
4041
- 使用 AI 侧边栏辅助写 SQL、解释查询(可选)
4142
- 通过 SSH 隧道访问远程数据库

docs/zh/Development/DEVELOPMENT.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,103 @@ bun run test:rust:unit
5151
bun run test:integration
5252
```
5353

54+
### 集成测试自动化(MySQL + MariaDB + Postgres + ClickHouse + SQL Server + DuckDB)
55+
56+
- 默认执行 `bun run test:integration` 会自动启动/销毁 MySQL、MariaDB、Postgres、ClickHouse 与 SQL Server 容器(DuckDB 使用本地临时文件,不依赖容器)。
57+
- 可通过 `IT_DB` 指定目标数据库:
58+
```bash
59+
IT_DB=mysql bun run test:integration
60+
IT_DB=mariadb bun run test:integration
61+
IT_DB=postgres bun run test:integration
62+
IT_DB=clickhouse bun run test:integration
63+
IT_DB=mssql bun run test:integration
64+
IT_DB=duckdb bun run test:integration
65+
IT_DB=all bun run test:integration
66+
```
67+
- 如需复用你本地已经启动的数据库(兼容旧流程),可设置:
68+
```bash
69+
IT_REUSE_LOCAL_DB=1 bun run test:integration
70+
```
71+
72+
### 集成测试常见环境变量(可选覆盖)
73+
74+
- MySQL: `MYSQL_HOST` `MYSQL_PORT` `MYSQL_USER` `MYSQL_PASSWORD` `MYSQL_DB`
75+
- MariaDB: `MARIADB_HOST` `MARIADB_PORT` `MARIADB_USER` `MARIADB_PASSWORD` `MARIADB_DB`
76+
- Postgres: `POSTGRES_HOST` `POSTGRES_PORT` `POSTGRES_USER` `POSTGRES_PASSWORD` `POSTGRES_DB`
77+
- ClickHouse: `CLICKHOUSE_HOST` `CLICKHOUSE_PORT` `CLICKHOUSE_USER` `CLICKHOUSE_PASSWORD` `CLICKHOUSE_DB`
78+
- SQL Server: `MSSQL_HOST` `MSSQL_PORT` `MSSQL_USER` `MSSQL_PASSWORD` `MSSQL_DB`
79+
- DuckDB: `DUCKDB_IT_DB_PATH`(可选)`DUCKDB_DB_PATH`(可选)
80+
- 兼容 Postgres 常见别名: `PG_HOST` `PG_PORT` `PGUSER` `PGPASSWORD` `PGDATABASE`
81+
82+
### 排障建议
83+
84+
- 镜像拉取慢:先手动执行 `docker pull mysql:8.0``docker pull mariadb:11``docker pull postgres:16-alpine``docker pull clickhouse/clickhouse-server:24.3``docker pull mcr.microsoft.com/mssql/server:2022-latest` 预热。
85+
- 端口冲突:集成测试默认使用 Docker 动态映射端口,通常不会冲突;如本地复用模式冲突,请调整 `*_PORT`
86+
- Apple 芯片兼容:若首次拉取较慢,建议预先拉取镜像并等待 Docker Desktop 完成架构层初始化。
87+
88+
### 推荐工作流
89+
90+
- 日常开发:优先执行 `test:unit` + `test:service`
91+
- 提交前:按需执行 `test:integration` 做数据库回归。
92+
- PR:CI 会固定执行集成测试作为质量兜底。
93+
94+
### 功能开发后怎么跑测试(实践版)
95+
96+
1. 开发过程中(高频、快速反馈)
97+
98+
- 先跑:
99+
```bash
100+
bun run test:unit
101+
bun run test:service
102+
```
103+
- 适用:前端逻辑、业务逻辑、小范围改动的快速验证。
104+
105+
2. 改动涉及数据库行为时(中频)
106+
107+
- 跑:
108+
```bash
109+
IT_DB=all bun run test:integration
110+
```
111+
- 或按需只跑单库:
112+
```bash
113+
IT_DB=mysql bun run test:integration
114+
IT_DB=mariadb bun run test:integration
115+
IT_DB=postgres bun run test:integration
116+
IT_DB=clickhouse bun run test:integration
117+
IT_DB=mssql bun run test:integration
118+
IT_DB=duckdb bun run test:integration
119+
```
120+
- 适用:连接参数、驱动逻辑、执行 SQL、表/库元数据、DDL/DML、类型映射相关改动。
121+
122+
3. 提交前(低频但建议)
123+
124+
- 至少跑一次:
125+
```bash
126+
IT_DB=all bun run test:integration
127+
```
128+
- PR 流水线会再次自动跑,作为最终兜底。
129+
130+
### 这套集成测试覆盖什么 / 不覆盖什么
131+
132+
- 能覆盖:
133+
- Rust 数据库层真实连库能力
134+
- 常见数据库操作链路(连接、建表、查询、元数据、DDL)
135+
- 驱动兼容与类型映射问题
136+
- 不覆盖:
137+
- 前端 UI 的“点点点”交互流程(这属于 E2E/UI 自动化范畴)
138+
- 纯视觉样式问题
139+
140+
### 什么时候可以不跑集成测试
141+
142+
- 仅改文案、样式、纯前端展示层,且不影响数据库交互。
143+
- 仅改与数据库完全无关的代码。
144+
- 快速迭代中间版本可不跑;合并前建议补跑一次。
145+
146+
### 容器清理说明
147+
148+
- 默认模式(未设置 `IT_REUSE_LOCAL_DB=1`)下,测试使用 testcontainers 拉起临时容器,测试结束后会自动销毁。
149+
- 设置 `IT_REUSE_LOCAL_DB=1` 时,测试会连接你手动准备的数据库实例,不会自动删除你自己的容器。
150+
54151
## 代码格式化
55152

56153
```bash

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "git+https://github.com/codeErrorSleep/dbpaw.git"
66
},
77
"private": true,
8-
"version": "0.2.9",
8+
"version": "0.3.0",
99
"type": "module",
1010
"scripts": {
1111
"dev": "vite",

scripts/db-onboard.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ $# -lt 1 ]]; then
5+
echo "Usage: scripts/db-onboard.sh <db> [--skip-gate] [--skip-matrix]"
6+
exit 1
7+
fi
8+
9+
db="$1"
10+
shift || true
11+
12+
skip_gate=0
13+
skip_matrix=0
14+
15+
for arg in "$@"; do
16+
case "$arg" in
17+
--skip-gate)
18+
skip_gate=1
19+
;;
20+
--skip-matrix)
21+
skip_matrix=1
22+
;;
23+
*)
24+
echo "[error] unknown option: $arg"
25+
echo "Usage: scripts/db-onboard.sh <db> [--skip-gate] [--skip-matrix]"
26+
exit 1
27+
;;
28+
esac
29+
done
30+
31+
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
32+
cd "${root_dir}"
33+
34+
context_file="src-tauri/tests/common/${db}_context.rs"
35+
integration_file="src-tauri/tests/${db}_integration.rs"
36+
command_file="src-tauri/tests/${db}_command_integration.rs"
37+
stateful_file="src-tauri/tests/${db}_stateful_command_integration.rs"
38+
tracker_file="docs/zh/Development/MYSQL_TEST_COVERAGE_GAP_TRACKER.md"
39+
40+
echo "[step] scaffold check: ${db}"
41+
missing=0
42+
for file in "${context_file}" "${integration_file}" "${command_file}" "${stateful_file}"; do
43+
if [[ ! -f "${file}" ]]; then
44+
echo "[missing] ${file}"
45+
missing=1
46+
else
47+
echo "[ok] ${file}"
48+
fi
49+
done
50+
51+
if [[ ${missing} -ne 0 ]]; then
52+
echo "[error] scaffold is incomplete for '${db}'."
53+
echo "[hint] finish scaffold first, then rerun scripts/db-onboard.sh ${db}"
54+
exit 1
55+
fi
56+
57+
if [[ ${skip_gate} -eq 0 ]]; then
58+
echo "[step] gate syntax check"
59+
bash -n scripts/test-integration.sh
60+
61+
echo "[step] compile smoke: ${db}_integration"
62+
cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_integration" --no-run
63+
64+
echo "[step] compile smoke: ${db}_command_integration"
65+
cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_command_integration" --no-run
66+
67+
echo "[step] compile smoke: ${db}_stateful_command_integration"
68+
cargo test --manifest-path src-tauri/Cargo.toml --test "${db}_stateful_command_integration" --no-run
69+
70+
echo "[step] integration gate run: IT_DB=${db}"
71+
IT_DB="${db}" bash scripts/test-integration.sh
72+
else
73+
echo "[skip] gate run skipped by --skip-gate"
74+
fi
75+
76+
if [[ ${skip_matrix} -eq 0 ]]; then
77+
echo "[step] matrix sync check"
78+
test_count="$(rg -n "async fn test_${db}_" src-tauri/tests --glob "*.rs" || true)"
79+
test_count="$(printf "%s\n" "${test_count}" | sed '/^$/d' | wc -l | tr -d ' ')"
80+
echo "[info] detected test functions for ${db}: ${test_count}"
81+
if [[ -f "${tracker_file}" ]]; then
82+
tracker_hits="$(rg -n "test_${db}_" "${tracker_file}" || true)"
83+
tracker_hits="$(printf "%s\n" "${tracker_hits}" | sed '/^$/d' | wc -l | tr -d ' ')"
84+
if [[ "${tracker_hits}" -eq 0 ]]; then
85+
echo "[warn] tracker has no '${db}' test entries yet: ${tracker_file}"
86+
echo "[next] sync capability matrix and command coverage sections for '${db}'"
87+
else
88+
echo "[ok] tracker already contains ${tracker_hits} '${db}' test entries"
89+
fi
90+
else
91+
echo "[warn] tracker file not found: ${tracker_file}"
92+
fi
93+
else
94+
echo "[skip] matrix sync check skipped by --skip-matrix"
95+
fi
96+
97+
echo "[done] db onboarding pipeline finished for '${db}'"

0 commit comments

Comments
 (0)