🐛 fix(driver): 修复驱动代理 revision 误触发重装并优化事务提示

This commit is contained in:
Syngnat
2026-06-12 11:07:41 +08:00
parent e83c9f5553
commit 5061ec081a
9 changed files with 172 additions and 66 deletions

View File

@@ -2181,11 +2181,11 @@ describe('QueryEditor external SQL save', () => {
'query-1',
);
expect(backendApp.DBQueryMulti).not.toHaveBeenCalled();
expect(textContent(renderer!.root)).toContain('事务待提交');
expect(textContent(renderer!.root)).toContain('提交');
expect(textContent(renderer!.root)).toContain('影响行数2');
await act(async () => {
await findExactButton(renderer!, '提交').props.onClick();
await findButton(renderer!, '提交').props.onClick();
});
await act(async () => {
await Promise.resolve();
@@ -2193,7 +2193,7 @@ describe('QueryEditor external SQL save', () => {
});
expect(backendApp.DBCommitTransaction).toHaveBeenCalledWith('tx-1');
expect(textContent(renderer!.root)).not.toContain('事务待提交');
expect(textContent(renderer!.root)).not.toContain('提交');
});
it('runs SQL editor WITH DML through a pending managed transaction', async () => {
@@ -2227,10 +2227,10 @@ describe('QueryEditor external SQL save', () => {
'query-1',
);
expect(backendApp.DBQueryMulti).not.toHaveBeenCalled();
expect(textContent(renderer!.root)).toContain('事务待提交');
expect(textContent(renderer!.root)).toContain('提交');
await act(async () => {
await findExactButton(renderer!, '提交').props.onClick();
await findButton(renderer!, '提交').props.onClick();
});
await act(async () => {
await Promise.resolve();
@@ -2277,7 +2277,8 @@ describe('QueryEditor external SQL save', () => {
expect.stringContaining('DELETE FROM users'),
'query-1',
);
expect(textContent(renderer!.root)).toContain('事务待提交,未提交 2 条变更语句');
expect(textContent(renderer!.root)).toContain('未提交');
expect(textContent(renderer!.root)).toContain('提交 (2)');
expect(storeState.sqlEditorPendingTransactions['tab-1']).toMatchObject({
id: 'tx-multi-dml',
statementCount: 2,
@@ -2405,7 +2406,7 @@ describe('QueryEditor external SQL save', () => {
'query-1',
);
expect(backendApp.DBQueryMulti).not.toHaveBeenCalled();
expect(textContent(renderer!.root)).toContain('事务待提交');
expect(textContent(renderer!.root)).toContain('提交');
});
it('auto commits SQL editor DML transactions after the configured delay', async () => {
@@ -2437,7 +2438,7 @@ describe('QueryEditor external SQL save', () => {
await Promise.resolve();
});
expect(textContent(renderer!.root)).toContain('事务待提交');
expect(textContent(renderer!.root)).toContain('3s 后自动提交');
expect(backendApp.DBCommitTransaction).not.toHaveBeenCalled();
await act(async () => {
@@ -2484,7 +2485,8 @@ describe('QueryEditor external SQL save', () => {
expect(backendApp.DBQueryMultiTransactional).toHaveBeenCalled();
expect(backendApp.DBQueryMulti).not.toHaveBeenCalled();
expect(textContent(renderer!.root)).toContain('事务执行成功,未提交 1 条变更语句,正在自动提交');
expect(textContent(renderer!.root)).toContain('自动提交');
expect(textContent(renderer!.root)).toContain('提交 (1)');
expect(backendApp.DBCommitTransaction).not.toHaveBeenCalled();
await act(async () => {
@@ -2494,7 +2496,7 @@ describe('QueryEditor external SQL save', () => {
});
expect(backendApp.DBCommitTransaction).toHaveBeenCalledWith('tx-auto-now');
expect(textContent(renderer!.root)).not.toContain('事务执行成功,未提交 1 条变更语句,正在自动提交');
expect(textContent(renderer!.root)).not.toContain('自动提交');
} finally {
vi.useRealTimers();
}
@@ -3730,12 +3732,13 @@ describe('QueryEditor external SQL save', () => {
expect(transactionSettingsSource).toContain("label: '立即'");
expect(source).toContain('QueryEditorTransactionToolbar');
expect(transactionToolbarSource).toContain("className={isV2Ui ? 'gn-v2-query-transaction-toolbar' : undefined}");
expect(transactionToolbarSource).toContain('事务待提交');
expect(transactionToolbarSource).toContain('未提交 ${statementCount} 条变更语句');
expect(transactionToolbarSource).toContain('事务执行成功${pendingCountText},正在自动提交');
expect(transactionToolbarSource).toContain("'未提交'");
expect(transactionToolbarSource).toContain('gn-v2-query-transaction-commit-button');
expect(transactionToolbarSource).toContain('gn-v2-toolbar-kbd');
expect(transactionToolbarSource).toContain("'自动提交中'");
expect(transactionToolbarSource).toContain('onFinish');
expect(toolbarSource).toContain('gn-v2-query-toolbar-action-group');
expect(transactionSettingsSource).toContain('style={isV2Ui ? undefined : { width: 160 }}');
expect(transactionSettingsSource).toContain('style={isV2Ui ? undefined : { width: 118 }}');
expect(toolbarSource).toContain('style={isV2Ui ? undefined : { width: 200 }}');
expect(toolbarSource).toContain('style={isV2Ui ? undefined : { width: 170 }}');
@@ -3752,7 +3755,7 @@ describe('QueryEditor external SQL save', () => {
expect(css).toContain('width: 140px !important;');
expect(css).toContain('width: 166px !important;');
expect(css).toContain('width: 132px !important;');
expect(css).toContain('width: 154px !important;');
expect(css).toContain('width: 118px !important;');
expect(css).toContain('width: 82px !important;');
expect(css).toContain('width: 34px !important;');
expect(css).toContain('@media (max-width: 900px)');

View File

@@ -30,7 +30,7 @@ const QueryEditorTransactionSettings: React.FC<QueryEditorTransactionSettingsPro
<Tooltip title="参考 DBeaverSQL 编辑器执行 INSERT/UPDATE/DELETE/MERGE/REPLACE 等 DML 时先进入 GoNavi 托管事务;手动提交需要手动提交/回滚,自动提交会在执行成功后自动 COMMIT。">
<Select
className={isV2Ui ? 'gn-v2-query-toolbar-select gn-v2-query-toolbar-transaction-mode-select' : undefined}
style={isV2Ui ? undefined : { width: 160 }}
style={isV2Ui ? undefined : { width: 118 }}
value={commitMode}
onChange={(mode) => onCommitModeChange(mode === 'auto' ? 'auto' : 'manual')}
options={[

View File

@@ -30,14 +30,20 @@ const QueryEditorTransactionToolbar: React.FC<QueryEditorTransactionToolbarProps
}
const statementCount = Math.max(0, Math.floor(Number(transaction.statementCount) || 0));
const pendingCountText = statementCount > 0
? `,未提交 ${statementCount} 条变更语句`
: '';
const pendingCount = statementCount > 0 ? statementCount : 1;
const statusText = transaction.commitMode === 'auto'
? autoCommitRemainingSeconds !== null && autoCommitRemainingSeconds > 0
? `事务待提交${pendingCountText}${autoCommitRemainingSeconds}s 后自动提交`
: `事务执行成功${pendingCountText},正在自动提交`
: `事务待提交${pendingCountText}`;
? `${autoCommitRemainingSeconds}s 后自动提交`
: '自动提交中'
: '未提交';
const commitLabel = isV2Ui
? (
<>
<span></span>
<span className="gn-v2-toolbar-kbd">{pendingCount}</span>
</>
)
: `提交 (${pendingCount})`;
return (
<div
@@ -54,11 +60,12 @@ const QueryEditorTransactionToolbar: React.FC<QueryEditorTransactionToolbarProps
{statusText}
</span>
<Button
className={isV2Ui ? 'gn-v2-query-transaction-commit-button' : undefined}
size="small"
type="primary"
onClick={() => onFinish('commit')}
>
{commitLabel}
</Button>
<Button
size="small"

View File

@@ -4840,8 +4840,8 @@ body[data-ui-version="v2"] .gn-v2-query-toolbar-max-rows-select {
}
body[data-ui-version="v2"] .gn-v2-query-toolbar-transaction-mode-select {
width: 154px !important;
flex: 0 0 154px !important;
width: 118px !important;
flex: 0 0 118px !important;
}
body[data-ui-version="v2"] .gn-v2-query-toolbar-transaction-delay-select {
@@ -4887,6 +4887,21 @@ body[data-ui-version="v2"] .gn-v2-query-toolbar-action-group.ant-btn-group > .an
display: none !important;
}
body[data-ui-version="v2"] .gn-v2-query-transaction-commit-button {
display: inline-flex !important;
align-items: center;
gap: 6px;
}
body[data-ui-version="v2"] .gn-v2-query-transaction-commit-button .gn-v2-toolbar-kbd {
margin-left: 0;
min-width: 18px;
justify-content: center;
background: rgba(255, 255, 255, 0.18);
color: #fff;
border-color: rgba(255, 255, 255, 0.22);
}
body[data-ui-version="v2"] .gn-v2-query-toolbar-icon-action.ant-btn,
body[data-ui-version="v2"] .gn-v2-query-toolbar .ant-btn-icon-only {
width: 34px !important;

View File

@@ -9,7 +9,7 @@ func init() {
"diros": "src-cc11b882e28fa5d4",
"starrocks": "src-83a6d81c91c7f5c8",
"sphinx": "src-a70c2cd4d223dac2",
"sqlserver": "src-84553484c72e7253",
"sqlserver": "src-6d5cf334034bce41",
"sqlite": "src-762863d48f653b89",
"duckdb": "src-df5d60ebb175bbbc",
"dameng": "src-596bebeaa016fc74",

View File

@@ -346,7 +346,7 @@ revision_file_changed_drivers() {
is_ignored_driver_agent_source_file() {
case "$1" in
*_test.go|frontend/*|internal/app/*)
*_test.go|frontend/*|internal/app/*|internal/appdata/*|internal/connection/*|internal/logger/*)
return 0
;;
esac
@@ -489,6 +489,22 @@ if [[ ${#changed_file_set[@]} -eq 0 ]]; then
exit 0
fi
has_revision_file_change=false
only_workflow_changes=true
for file in "${!changed_file_set[@]}"; do
case "$file" in
internal/db/driver_agent_revisions_gen.go)
has_revision_file_change=true
only_workflow_changes=false
;;
.github/workflows/dev-build.yml|.github/workflows/release.yml)
;;
*)
only_workflow_changes=false
;;
esac
done
declare -a forced_changed_drivers=()
forced_driver_seen="|"
for file in "${!changed_file_set[@]}"; do
@@ -527,6 +543,12 @@ for file in "${!changed_file_set[@]}"; do
exit 0
;;
.github/workflows/dev-build.yml|.github/workflows/release.yml)
if [[ "$has_revision_file_change" == "true" ]]; then
continue
fi
if [[ "$only_workflow_changes" == "true" && -f internal/db/driver_agent_revisions_gen.go ]]; then
continue
fi
echo "检测到 driver-agent 构建/发布工作流变更;保守构建全部 driver-agent$file" >&2
all_drivers_csv
exit 0

View File

@@ -11,9 +11,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$SCRIPT_DIR"
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-detect-driver-revisions.XXXXXX")"
tmpdir_connection=""
tmpdir_script=""
cleanup() {
rm -rf "$tmpdir"
if [[ -n "$tmpdir_connection" ]]; then
rm -rf "$tmpdir_connection"
fi
if [[ -n "$tmpdir_script" ]]; then
rm -rf "$tmpdir_script"
fi
@@ -50,6 +54,33 @@ GOEOF
fi
)
tmpdir_connection="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-detect-connection-change.XXXXXX")"
git init -q "$tmpdir_connection"
mkdir -p "$tmpdir_connection/tools" "$tmpdir_connection/internal/connection"
cp tools/detect-changed-driver-agents.sh "$tmpdir_connection/tools/detect-changed-driver-agents.sh"
cat >"$tmpdir_connection/internal/connection/types.go" <<'GOEOF'
package connection
type ConnectionConfig struct {
Type string `json:"type"`
}
GOEOF
(
cd "$tmpdir_connection"
git add .
git -c user.name=GoNavi -c user.email=gonavi@example.test commit -q -m initial
base="$(git rev-parse HEAD)"
perl -0pi -e 's/Type string/RedisSentinelLabel string `json:"redisSentinelLabel,omitempty"`\n\tType string/' internal/connection/types.go
git add internal/connection/types.go
git -c user.name=GoNavi -c user.email=gonavi@example.test commit -q -m 'add redis-only connection field'
actual="$(bash ./tools/detect-changed-driver-agents.sh --base "$base" --head HEAD)"
if [[ -n "$actual" ]]; then
echo "expected connection-only field change to keep driver-agent detection empty, got: ${actual}" >&2
exit 1
fi
)
tmpdir_script="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-detect-script-change.XXXXXX")"
git init -q "$tmpdir_script"
mkdir -p "$tmpdir_script/tools"

View File

@@ -4,6 +4,8 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$SCRIPT_DIR"
SCRIPT_DIR_WINDOWS="$(pwd -W 2>/dev/null || true)"
SCRIPT_DIR_WINDOWS="${SCRIPT_DIR_WINDOWS//\\//}"
DEFAULT_DRIVERS=(mariadb oceanbase diros starrocks sphinx sqlserver sqlite duckdb dameng kingbase highgo vastbase opengauss iris mongodb tdengine clickhouse elasticsearch)
OUTPUT_FILE="internal/db/driver_agent_revisions_gen.go"
@@ -145,6 +147,11 @@ elasticsearch:internal/db/elasticsearch_helpers.go)
should_include_source_file() {
local driver="$1"
local identity="$2"
case "$identity" in
internal/appdata/*|internal/connection/*|internal/logger/*)
return 1
;;
esac
if [[ "$identity" == internal/db/* ]]; then
should_include_internal_db_file "$driver" "$identity"
return
@@ -193,6 +200,7 @@ fi
goos="${target_platform%%/*}"
goarch="${target_platform##*/}"
gomodcache="$(go env GOMODCACHE)"
gomodcache="${gomodcache//\\//}"
declare -a drivers=()
if [[ -n "$driver_csv" ]]; then
@@ -277,18 +285,23 @@ fingerprint_driver() {
} >"$tmp"
while IFS= read -r file; do
file="${file//\\//}"
[[ -n "$file" && -f "$file" ]] || continue
case "$file" in
"$SCRIPT_DIR"/*)
identity="${file#$SCRIPT_DIR/}"
;;
"$gomodcache"/*)
identity="gomod/${file#$gomodcache/}"
;;
*)
identity="$file"
;;
esac
if [[ -n "$SCRIPT_DIR_WINDOWS" && "$file" == "$SCRIPT_DIR_WINDOWS"/* ]]; then
identity="${file#$SCRIPT_DIR_WINDOWS/}"
else
case "$file" in
"$SCRIPT_DIR"/*)
identity="${file#$SCRIPT_DIR/}"
;;
"$gomodcache"/*)
identity="gomod/${file#$gomodcache/}"
;;
*)
identity="$file"
;;
esac
fi
if [[ "$identity" == "$OUTPUT_FILE" ]]; then
continue
fi

View File

@@ -11,44 +11,30 @@ extract_revision() {
sed -n "s/.*\"${driver}\"[[:space:]]*:[[:space:]]*\"\\([^\"]*\\)\".*/\\1/p" "$file" | head -n 1
}
run_case() {
local platform="$1"
local drivers="$2"
local tmpdir
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-generate-driver-revisions.XXXXXX")"
trap 'rm -rf "$tmpdir"' RETURN
rsync -a --exclude .git ./ "$tmpdir/" >/dev/null
(
cd "$tmpdir"
GONAVI_DRIVER_REVISION_JOBS=1 bash ./tools/generate-driver-agent-revisions.sh --platform "$platform" --drivers "$drivers" >/dev/null
cat internal/db/driver_agent_revisions_gen.go
)
copy_repo_to_tmp() {
local target="$1"
git ls-files -z | tar --null -T - -cf - | (cd "$target" && tar -xf -)
}
darwin_output="$(run_case darwin/arm64 mariadb,duckdb)"
windows_output="$(run_case windows/amd64 mariadb,duckdb)"
tmpdir_platform="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-generate-driver-revisions-platform.XXXXXX")"
tmpdir_connection="$(mktemp -d "${TMPDIR:-/tmp}/gonavi-generate-driver-revisions-connection.XXXXXX")"
darwin_file="$(mktemp "${TMPDIR:-/tmp}/gonavi-darwin-revisions.XXXXXX")"
windows_file="$(mktemp "${TMPDIR:-/tmp}/gonavi-windows-revisions.XXXXXX")"
cleanup() {
rm -rf "$tmpdir_platform" "$tmpdir_connection"
rm -f "$darwin_file" "$windows_file"
}
trap cleanup EXIT
printf '%s\n' "$darwin_output" >"$darwin_file"
printf '%s\n' "$windows_output" >"$windows_file"
copy_repo_to_tmp "$tmpdir_platform"
darwin_mariadb="$(extract_revision "$darwin_file" mariadb)"
windows_mariadb="$(extract_revision "$windows_file" mariadb)"
if [[ -z "$darwin_mariadb" || -z "$windows_mariadb" ]]; then
echo "expected mariadb revision to be generated for both platforms" >&2
exit 1
fi
if [[ "$darwin_mariadb" == "$windows_mariadb" ]]; then
echo "expected mariadb revision to differ between darwin/arm64 and windows/amd64, got identical value: $darwin_mariadb" >&2
exit 1
fi
(
cd "$tmpdir_platform"
GONAVI_DRIVER_REVISION_JOBS=1 bash ./tools/generate-driver-agent-revisions.sh --platform darwin/arm64 --drivers duckdb >/dev/null
cp internal/db/driver_agent_revisions_gen.go "$darwin_file"
GONAVI_DRIVER_REVISION_JOBS=1 bash ./tools/generate-driver-agent-revisions.sh --platform windows/amd64 --drivers duckdb >/dev/null
cp internal/db/driver_agent_revisions_gen.go "$windows_file"
)
darwin_duckdb="$(extract_revision "$darwin_file" duckdb)"
windows_duckdb="$(extract_revision "$windows_file" duckdb)"
@@ -61,4 +47,33 @@ if [[ "$darwin_duckdb" == "$windows_duckdb" ]]; then
exit 1
fi
copy_repo_to_tmp "$tmpdir_connection"
(
cd "$tmpdir_connection"
GONAVI_DRIVER_REVISION_JOBS=1 bash ./tools/generate-driver-agent-revisions.sh --platform windows/amd64 --drivers sqlserver >/dev/null
before_file="$(mktemp "${TMPDIR:-/tmp}/gonavi-sqlserver-revision-before.XXXXXX")"
after_file="$(mktemp "${TMPDIR:-/tmp}/gonavi-sqlserver-revision-after.XXXXXX")"
cleanup_sqlserver_revision_files() {
rm -f "$before_file" "$after_file"
}
trap cleanup_sqlserver_revision_files EXIT
cp internal/db/driver_agent_revisions_gen.go "$before_file"
perl -0pi -e 's/RedisSentinelMaster string/RedisSentinelLabel string `json:"redisSentinelLabel,omitempty"`\n\tRedisSentinelMaster string/' internal/connection/types.go
GONAVI_DRIVER_REVISION_JOBS=1 bash ./tools/generate-driver-agent-revisions.sh --platform windows/amd64 --drivers sqlserver >/dev/null
cp internal/db/driver_agent_revisions_gen.go "$after_file"
before_sqlserver="$(extract_revision "$before_file" sqlserver)"
after_sqlserver="$(extract_revision "$after_file" sqlserver)"
if [[ -z "$before_sqlserver" || -z "$after_sqlserver" ]]; then
echo "expected sqlserver revision to be generated before and after connection-only change" >&2
exit 1
fi
if [[ "$before_sqlserver" != "$after_sqlserver" ]]; then
echo "expected Redis-only connection field change to keep sqlserver revision stable, before=$before_sqlserver after=$after_sqlserver" >&2
exit 1
fi
)
echo "generate-driver-agent-revisions platform test passed"