Skip to content

jacoyutorius/database-diff-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Verification Tool

Amazon RDS (MySQL) から TiDB へのデータ移行整合性を検証する CLI ツールです。 Ruby で実装されており、大量データの移行検証を効率的に行うために設計されています。

特徴

  • 行数チェック: ソースとターゲットのテーブル行数が一致することを確認します。
  • 直近データ検証: プライマリキー (PK) の降順で最新 100 件を取得し、データ内容が完全に一致するか検証します。
  • 大規模データ対応: 全件比較を行わないため、数億レコード規模のテーブルでも高速に検証可能です。

必要要件

  • Ruby 2.7+
  • MySQL / TiDB へのネットワークアクセス

インストール

# 依存ライブラリのインストール
bundle install --path vendor/bundle

設定

  1. 設定ファイルのテンプレートをコピーします。
cp config.yml.example config.yml
  1. config.yml を編集し、ソース (RDS) と ターゲット (TiDB) の接続情報を入力してください。
source:
  host: "source-rds.example.com"
  username: "admin"
  password: "password"
  database: "app_db"

target:
  host: "media-tidb.example.com"
  username: "root"
  password: "password"
  database: "app_db"
  port: 4000

使い方

検証したいテーブル名をカンマ区切りで指定して実行します。

bundle exec bin/db_verify verify --tables users,orders,products

出力例

Verifying table: users ...
Verifying table: orders ...

Verification Report:
+--------+-----------+-------------------+
| Table  | Row Count | Latest 100 Data   |
+--------+-----------+-------------------+
| users  | OK        | OK                |
| orders | OK        | MISMATCH (3 rows) |
+--------+-----------+-------------------+

[orders] Detailed Mismatches (Top 5):
{:id=>1024, :type=>:mismatch, :columns=>["status"], :source_val=>{"status"=>"shipped"}, :target_val=>{"status"=>"processing"}}

ローカル開発 / テスト

Docker Compose を使って、検証用のダミー環境をローカルに立ち上げることができます。

  1. DB 起動

    docker compose up -d
    • Source DB: Port 3307 (MySQL 8.0)
    • Target DB: Port 3308 (MySQL 8.0)
    • docker/target/init.sql により、users テーブルの ID=120 のレコードが意図的に不整合になっています。
  2. 検証実行

    bundle exec bin/db_verify verify --config config-docker.yml --tables users

    実行結果として、Latest 100 DataMISMATCH になることが確認できます。

  3. 終了

    docker compose down -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages