- Continuous Monitoring: Runs long-lived watcher threads for Git and MySQL.
- Git Branch Tracking: Detects current branch and branch switches.
- Schema Snapshotting: Saves normalized schema snapshots in
tables/<table_name>/schema.sql. - Automatic Migrations:
- Detects added columns and generates
ALTER TABLE ... ADD ...statements. - Detects removed columns and generates
ALTER TABLE ... DROP ...statements. - Creates timestamped
_up.sqland_down.sqlmigration files.
- Detects added columns and generates
- Branch-Aware SQL Output:
mainbranch: writes baseline snapshots underdbtables/main/schemas/and full snapshot filedbtables/main.sql.- Non-
mainbranches: writes delta pairs using timestamp styledbtables/<branch>/<timestamp>_<table>_up.sqland_down.sql.
- History Tracking: Logs schema modifications in
tables/<table_name>/history.txt. - App Logging: Writes runtime logs to
logs/app.log. - Environment Configuration: Loads database credentials directly from a
.envfile.
- GCC compiler
- MySQL Client libraries (
libmysqlclient-dev) - Libgit2 (
libgit2-dev) - Linked but currently unused, ready for future git integration. - Pthread
- Clone the repository.
- Install dependencies (Ubuntu/Debian):
sudo apt-get install libmysqlclient-dev libgit2-dev
- Copy the example environment file:
cp .example.env .env
- Edit
.envwith your database credentials:DB_HOST=127.0.0.1 DB_USER=root DB_PASS=password DB_NAME=mydb DB_PORT=3306
To compile the project:
makeThis creates the executable at build/main.
To build and run in foreground:
make runTo run as background process:
make run-dTo stop:
make stop-dThe program connects to the DB, starts Git/MySQL watcher threads, and keeps monitoring. Output will look like:
DB Host: 127.0.0.1
...
Connection test successful!
Starting database watcher for mydb...
Current branch: main
When changes are detected, files are generated like:
tables/
└── test_table/
├── schema.sql
├── history.txt
└── migrations/
├── 20231027100000_test_table_up.sql
└── 20231027100000_test_table_down.sql
dbtables/
├── main.sql
├── main/
│ └── schemas/
│ └── <table>.sql
└── <non-main-branch>/
├── 20231027100000_test_table_up.sql
└── 20231027100000_test_table_down.sql
logs/
└── app.log
To remove build artifacts:
make clean