11

MySQL Workbenchを使用して、アプリケーションのデータベーススキーマを維持しています。.mwbワークベンチが使用するファイル(zip形式のXMLドキュメント)は、Subversionリポジトリに保存されます。

このファイルはSubversionによってバイナリデータとして扱われるためsvn diff、たとえばコミットする前に、変更を表示するために使用することはできません。

データは実際にはXMLであるため、とにかく差分を表示する方法があるのではないかと思います。前にファイルを解凍するスクリプトや、へのプラグインなどsvn diffです。

理想的な解決策はこれを可能にするでしょう:

$ svn diff db-model.mwb

またはMeldを使用することもできます:

$ meld db-model.mwb

これを達成するためにどのようなアプローチを考えることができますか?たぶん他の誰かがSubversionでアーカイブされたテキストファイルのdiffを表示するというこの問題を抱えていました。

4

2 に答える 2

8

Subversionを使用すると、外部の差分ツールを使用できます。できることは、ラッパースクリプトを記述し、それを「diff」コマンドとして使用するようにSubversionに指示することです。ラッパーは、Subversionから取得した引数を解析して、「左」と「右」のファイル名を選択し、それらを操作して、Subversionが成功または失敗として解釈するエラーコードを返します。あなたの場合、ラッパーはXMLファイルを解凍し、解凍した結果を「diff」または選択した別のツールに渡すことができます。

Subversionは、チェックイン時に「バイナリ」として検出された差分ファイルを無効にします。「-force」オプションを使用すると、このチェックをオーバーライドできるため、入力ファイルがチェックインされている場合でもラッパースクリプトが実行されます。バイナリとして。

于 2009-09-01T08:27:06.290 に答える
3

TortoiseSVNおよびTortoiseGitと統合できるワークベンチファイルのdiffスクリプトを作成しました。これは、JimLewisが提案することを正確に実行します。アーカイブから実際のXMLを抽出してdiffします。

このスクリプトは、diff内のすべてのptr -Attributeノイズも除去します。マージは不可能であり、もう少し複雑になります(ptr属性がどのように動作するかを調べ、XMLをアーカイブに再パックし、アーカイブ内の他のメタデータとは何ですか?、...)

Pythonスクリプトは、CC-BY3.0のpastebinで入手できます。

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)
于 2012-06-12T14:36:22.337 に答える