Commit 7ba546c8 authored by nanahira's avatar nanahira

test sql merge

parent a1821c5b
Pipeline #36056 passed with stage
in 45 seconds
*.cdb merge=sqlite-merge diff=sqlite-diff
#!/bin/sh
# Input SQLite database path
DB="$1"
# Locate sqlite3 binary
if [ -n "$SQLITE3_BIN" ]; then
SQLITE3="$SQLITE3_BIN"
elif command -v sqlite3 >/dev/null 2>&1; then
SQLITE3="sqlite3"
elif command -v sqlite3.exe >/dev/null 2>&1; then
SQLITE3="sqlite3.exe"
elif [ -x "./bin/sqlite3" ]; then
SQLITE3="./bin/sqlite3"
elif [ -x "./bin/sqlite3.exe" ]; then
SQLITE3="./bin/sqlite3.exe"
else
echo "❌ Error: sqlite3 binary not found."
echo "Please set the SQLITE3_BIN environment variable or install sqlite3."
exit 1
fi
# Run .dump and filter out noise
"$SQLITE3" "$DB" .dump | grep -v '^--' | grep -v '^PRAGMA'
#!/bin/sh
# Locate sqlite3 binary
if [ -n "$SQLITE3_BIN" ]; then
SQLITE3="$SQLITE3_BIN"
elif command -v sqlite3 >/dev/null 2>&1; then
SQLITE3="sqlite3"
elif command -v sqlite3.exe >/dev/null 2>&1; then
SQLITE3="sqlite3.exe"
elif [ -x "./bin/sqlite3" ]; then
SQLITE3="./bin/sqlite3"
elif [ -x "./bin/sqlite3.exe" ]; then
SQLITE3="./bin/sqlite3.exe"
else
echo "❌ Error: sqlite3 binary not found."
echo "Please set the SQLITE3_BIN environment variable or install sqlite3."
exit 1
fi
BASE="$1"
OURS="$2"
THEIRS="$3"
RESULT="$2"
FILE_PATH="$5"
CONFLICT_FILE="$FILE_PATH.sql"
TMPDIR=$(mktemp -d) || exit 1
# 手动清理函数
cleanup() {
rm -rf "$TMPDIR"
}
# 不用 trap,因为 sh 没有 EXIT trap,靠手动调用
"$SQLITE3" "$BASE" .dump > "$TMPDIR/base.sql" || { cleanup; exit 1; }
"$SQLITE3" "$OURS" .dump > "$TMPDIR/ours.sql" || { cleanup; exit 1; }
"$SQLITE3" "$THEIRS" .dump > "$TMPDIR/theirs.sql" || { cleanup; exit 1; }
git merge-file -p "$TMPDIR/ours.sql" "$TMPDIR/base.sql" "$TMPDIR/theirs.sql" > "$TMPDIR/merged.sql"
MERGE_EXIT_CODE=$?
if grep '^<<<<<<<' "$TMPDIR/merged.sql" >/dev/null; then
echo "❌ Merge conflict detected. Please resolve:"
echo " --> $CONFLICT_FILE"
cp "$TMPDIR/merged.sql" "$CONFLICT_FILE"
cleanup
exit 1 # 保留冲突文件,人工处理,故不 cleanup
fi
echo '' > "$RESULT"
"$SQLITE3" "$RESULT" < "$TMPDIR/merged.sql" || {
echo "❌ Failed to import merged SQL"
echo " --> $CONFLICT_FILE"
cp "$TMPDIR/merged.sql" "$CONFLICT_FILE"
cleanup
exit 1
}
echo "✅ Merged successfully to $FILE_PATH"
cleanup
exit 0
#!/bin/sh
set -e
# Attempt to find sqlite3, including environment override and local bin/
find_sqlite3() {
if [ -n "$SQLITE3_BIN" ] && [ -x "$SQLITE3_BIN" ]; then
echo "$SQLITE3_BIN"
return 0
fi
if command -v sqlite3 >/dev/null 2>&1; then
echo "sqlite3"
return 0
fi
if command -v sqlite3.exe >/dev/null 2>&1; then
echo "sqlite3.exe"
return 0
fi
if [ -x "./bin/sqlite3" ]; then
echo "./bin/sqlite3"
return 0
fi
if [ -x "./bin/sqlite3.exe" ]; then
echo "./bin/sqlite3.exe"
return 0
fi
return 1
}
install_sqlite3_windows() {
echo "🔍 sqlite3 not found — downloading for Windows..."
mkdir -p bin
ZIP_URL="https://sqlite.org/2025/sqlite-tools-win-x64-3490200.zip"
ZIP_FILE="bin/sqlite3.zip"
# Only download if the zip file or binaries aren't already there
if ! [ -f "$ZIP_FILE" ] || ! find bin -iname "sqlite3.exe" | grep -q .; then
echo "⬇️ Downloading SQLite tools..."
curl -sL -o "$ZIP_FILE" "$ZIP_URL" || {
echo "❌ Failed to download SQLite zip from $ZIP_URL"
exit 1
}
echo "📦 Extracting..."
unzip -o "$ZIP_FILE" -d bin || {
echo "❌ Failed to unzip SQLite tools"
exit 1
}
else
echo "✅ sqlite3 already exists in bin/, skipping download"
fi
}
# --- Main logic ---
SQLITE3_PATH=$(find_sqlite3)
if [ -z "$SQLITE3_PATH" ]; then
UNAME=$(uname | tr '[:upper:]' '[:lower:]')
if echo "$UNAME" | grep -qi "mingw\\|msys\\|cygwin"; then
install_sqlite3_windows
SQLITE3_PATH=$(find_sqlite3)
else
echo "❌ sqlite3 not found in PATH or ./bin/"
echo "Please install sqlite3 manually (e.g., via apt, brew, or your package manager)."
exit 1
fi
fi
echo "✅ Using sqlite3: $SQLITE3_PATH"
export SQLITE3_BIN="$SQLITE3_PATH"
# --- Git configuration ---
git config merge.sqlite-merge.name "SQLite dump merge"
git config merge.sqlite-merge.driver "scripts/sqlite-merge.sh %O %A %B %L %P"
git config diff.sqlite-diff.textconv "scripts/sqlite-diff.sh"
git config diff.sqlite-diff.prompt false
echo "✅ Git merge & diff drivers configured successfully."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment