我使用MySQL工作台保持一个应用程序的数据库模式。 该.mwb
该工作台使用文件,这是一个压缩的XML文档,保存在Subversion库。
该文件被视为由Subversion的二进制数据,所以我不能使用svn diff
提交之前表现出的变化,例如。
由于数据是真的XML,我想可能有一些办法反正显示DIFF,也许有些脚本之前解压缩文件,或者一些插件svn diff
。
理想的解决方案将允许这样的:
$ svn diff db-model.mwb
甚至使用MELD:
$ meld db-model.mwb
你能想到什么办法做到这一点? 也许别人已表示在颠覆归档文本文件差异的这个问题。
Subversion允许使用外部差异的工具 。 你可以做的是写一个脚本,并且告诉Subversion使用它作为其“差异”命令。 你会包装解析它从Subversion获取参数挑出来的“左”和“右”的文件名,对它们进行操作,并返回一个错误代码,Subversion会解释为成功或失败。 在你的情况下,包装可以解压缩XML文件,并通过解压缩后的结果,以“差异”或您选择的另一个工具。
Subversion会不惜被检测为“二进制”当他们在已检查DIFF-ING的文件。该“--force”选项,您可以覆盖此检查,所以即使输入文件中检查你的包装脚本将运行作为二进制文件。
我已经写了可以与TortoiseSNV和TortoiseGit集成工作台的文件,这将究竟做什么吉姆·刘易斯提出一个差异脚本:提取从归档中实际的XML和diff的它。
该脚本也将消除DIFF所有PTR -Attribute噪音。 合并是不可能的,会更复杂一些(发现PTR -attributes会如何表现,重新包装成XML存档,什么是在档案中的其他元数据,......)
该Python脚本可在以下引擎收录CC-BY 3.0:
http://pastebin.com/AcD7dBNH
# extensions: mwb
# TortoiseSVN Diff script for MySQL Workbench scheme files
# 2012 by Oliver Iking, Z-Software GmbH, oliverikingREPLACETHISWITHANATz-software.net, http://www.z-software.net/
# This work is licensed under a Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/
# Will produce two diffable documents, which don't resemble the FULL MWB content, but the scheme relevant data.
# Merging is not possible
# Open your TortoiseSVN (or TortoiseSomething) settings, go to the "Diff Viewer" tab and click on "Advanced". Add
# a row with the extension ".mwb" and a command line of
# "path\to\python.exe" "path\to\diff-mwb.py" %base %mine
# Apply changes and now you can diff mysql workbench scheme files
import sys
import zipfile
import os
import time
import tempfile
import re
# mysql workbench XML will have _ptr_ attributes which are modified on each save for almost each XML node. Remove the visual litter,
# make actual changes stand out.
def sanitizeMwbXml( xml ):
return re.sub('_ptr_="([0-9a-fA-F]{8})"', '', xml)
try:
if len(sys.argv) < 2:
print("Not enough parameters, cannot diff documents!")
sys.exit(1)
docOld = sys.argv[1]
docNew = sys.argv[2]
if not os.path.exists(docOld) or not os.path.exists(docNew):
print("Documents don't exist, cannot diff!")
sys.exit(1)
# Workbench files are actually zip archives
zipA = zipfile.ZipFile( docOld, 'r' )
zipB = zipfile.ZipFile( docNew, 'r' )
tempSubpath = os.tempnam(None,"mwbcompare")
docA = os.path.join( tempSubpath, "mine.document.mwb.xml" )
docB = os.path.join( tempSubpath, "theirs.document.mwb.xml" )
os.makedirs( tempSubpath )
if os.path.exists(docA) or os.path.exists(docB):
print("Cannot extract documents, files exist!")
sys.exit(1)
# Read, sanitize and write actual scheme XML contents to temporary files
docABytes = sanitizeMwbXml(zipA.read("document.mwb.xml" ))
docBBytes = sanitizeMwbXml(zipB.read("document.mwb.xml" ))
docAFile = open(docA, "w")
docBFile = open(docB, "w")
docAFile.write(docABytes)
docBFile.write(docBBytes)
docAFile.close()
docBFile.close()
os.system("TortoiseProc /command:diff /path:\"" + docA + "\" /path2:\"" + docB + "\"");
# TortoiseProc will spawn a subprocess so we can't delete the files. They're in the tempdir, so they
# will be cleaned up eventually
#os.unlink(docA)
#os.unlink(docB)
sys.exit(0)
except Exception as e:
print str(e)
# Sleep, or the command window will close
time.sleep(5)