Repository navigation
feat(connections): compare the structure of two schemas - #104
Merged
Merged
Conversation
Right-click a schema, set it as the comparison base, then compare another schema with it, on the same connection or another one. The report lists the tables only one side has and the columns that were added, removed, or differ in type, NULL or primary key. Only catalog reads are run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
想確認本機的資料庫跟正式機的結構有沒有對上(migration 有沒有漏跑、本機是不是多開了欄位),現在只能兩邊各開一個 ER 圖或一張一張表看。DBeaver 的結構比對只有付費版有,所以我加了一個簡單版的。
用法:在 Schema 面板的 schema 上按右鍵 →「設為比對基準」,再到另一個 schema 按右鍵 →「與 X(連線)比對結構」。兩個 schema 可以在同一個連線,也可以在不同連線。
比的是
Catalog::schema_columns讀得到的東西,跟 ER 圖讀的一樣:名稱不分大小寫(MySQL 在 Windows 會轉小寫),型別不分大小寫也不管空白(
VARCHAR( 255 )跟varchar(255)算一樣)。欄位順序、索引、外鍵、預設值這版沒有比。不同引擎之間比的話,型別名稱本來就不一樣(INTEGER對int),會列成型別不同。結果是一個對話框,紅色是只有 A 有,綠色是只有 B 有,黃色是不一樣的,可以「複製為文字」貼到 issue 或訊息裡。兩邊的結構是同時讀的,只有讀取,所以 Production 上也可以用。如果某一邊欄位太多、
schema_columns沒讀完,報告最上面會提醒。改的檔案:
crates/locus-core/src/connection/schema_diff.rs:比對和報告文字,純邏輯,附 7 個測試crates/app/src/connections/compare.rs:連線(沒連的話先連)、兩邊同時讀、顯示對話框crates/app/src/connections/objects.rs、objects/load.rs、objects/render.rs:記住比對基準、schema 右鍵選單的兩個項目crates/app/src/shell/mod.rs:接上ObjectsEvent::CompareSchemascrates/app/locales/*.yml:schema_compare.*,三種語言crates/locus-core/src/connection/mod.rs、docs/architecture.md:新模組.changeset/schema-compare.md(minor)fmt、
clippy -D warnings、typos都過,cargo test -p locus-core --lib406 個、cargo test -p app --bins86 個,都過。實際開起來試過:兩個 SQLite 連線的
main互相比,對話框上面有 A、B 分別是哪個連線,只有一邊有的資料表都有列出來。MySQL、PostgreSQL 之間的比對我只有單元測試,還沒接真的資料庫試。之後可以再加的:比索引和外鍵、從差異產生
ALTER語法。