
GoMetaSync is an open-source tool written in Go that automatically detects database schema drift and keeps your Go structs in sync with live PostgreSQL databases.
It generates snapshots of your database metadata, detects differences between versions, and regenerates Go models dynamically β ensuring your application code always matches the actual database schema.
Tech Stack
- Language: Go 1.23+
- Database: PostgreSQL
- Serialization: JSON, YAML
β‘ Quick Start
# 1. Install CLI
go install github.com/Saba101/GoMetaSync/cmd/[email protected]
# 2. Configure connection (edit configs/dev.yml)
# 3. Generate snapshot
gometasync --mode snapshot --config configs/dev.yml --new snapshots/dev.json
# 4. Detect drift
gometasync --mode diff --old snapshots/dev.json --new snapshots/dev2.json
# 5. Generate Go structs
gometasync --mode generate --new snapshots/dev2.json --out generated_models
π§ Overview
Database schemas evolve constantly β new columns, renamed tables, type changes, or even dropped fields.
In fast-moving teams, these changes often break existing application code that relies on hardcoded models or outdated ORM mappings.
GoMetaSync solves this by introducing a metadata synchronization layer:
- It periodically scans and snapshots your database schema.
- It detects any drift between environments (e.g., DEV vs PROD).
- It regenerates Go structs automatically from live metadata.
This makes GoMetaSync an excellent fit for:
- Teams managing multiple environments (DEV, QA, STAGE, PROD)
- Projects that rely on code-generated models
- Data engineering pipelines that need metadata consistency
βοΈ Core Features
β
Detects schema drift across databases and environments
β
Generates Go structs directly from live database schemas
β
Produces metadata snapshots as versioned JSON files
β
Works with PostgreSQL out of the box
β
Extensible architecture β future support for MySQL, MSSQL, and SQLite
β
No ORM dependency β simple, portable, pure Go
π§© Example Drift Output
β
New table: dataflow_server.public.schedule
β
New column: dataflow_server.public.job_logs.error_message (text)
β οΈ Type changed: datasource_server.public.users.age (integer β text)
β Column dropped: datasource_server.public.data_source.secret_key
β
Project Structure
GoMetaSync/
GoMetaSync/
βββ cmd/
β βββ gometasync/
β βββ main.go
βββ internal/
β βββ config/ # YAML config loader
β βββ collector/ # Database metadata reader
β βββ snapshot/ # Save/load JSON snapshots + diff
β βββ generated_models/ # Auto-generated Go structs
β βββ models/ # Snapshot structs
βββ configs/ # Database connection configs
βββ snapshots/ # Generated snapshot JSON files
βοΈ Configuration Example
configs/dev.yml
env: LOCAL
databases:
- name: dataflow_server
# Option A β DSN:
dsn: postgres://admin:<password>@localhost:<port>/<database>?sslmode=disable
# Option B β explicit config:
host: "localhost"
port: <port>
username: "admin"
password: "<password>"
database: "<database>"
synchronize: false
ssl: false
rejectUnauthorized: false
π§± Installation
Option 1 β Install via Go (Recommended)
GoMetaSync can now be installed globally as a CLI tool:
go install github.com/Saba101/GoMetaSync/cmd/[email protected]
This will download and build the latest tagged version from GitHub.
Once installed, you can run it from anywhere:
gometasync --help
Option 2 β Build from Source (For Contributors)
If you want to run or modify the code manually:
git clone https://github.com/Saba101/GoMetaSync.git
cd GoMetaSync
go mod tidy
go run cmd/gometasync/main.go --help
π§ Usage Examples
1. Generate a Snapshot of Your Database
Using package:
gometasync --mode snapshot \
--config configs/dev.yml \
--new snapshots/dev-1.json
Using CLI:
go run cmd/gometasync/main.go \
--mode snapshot \
--config configs/dev.yml \
--new snapshots/dev-1.json
2. Detect Schema Drift
Using package:
gometasync --mode diff \
--old snapshots/dev-1.json \
--new snapshots/dev-2.json
Using CLI:
go run cmd/gometasync/main.go \
--mode diff \
--old snapshots/dev-1.json \
--new snapshots/dev-2.json
3. Generate Go Structs
Using package:
gometasync --mode generate \
--new snapshots/dev-2.json \
--out generated_models
Using CLI:
go run cmd/gometasync/main.go \
--mode generate \
--new snapshots/dev-2.json \
--out generated_models
π§ͺ Example Generated Struct
// Code generated automatically. DO NOT EDIT.
package generated_models
import "time"
type Users struct {
Id string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
}
π€ Contributions
- Pull requests, ideas, and feedback are welcome!
- Fork the repository
- Create a feature branch (feature/your-idea)
- Commit your changes
- Submit a pull request π
π Acknowledgements
- Inspired by schema management techniques in Superset, Metabase, and dbt
- Built for Go open-source community
π« Connect
If you find this useful, please β the repo and share feedback!
For collaboration or feature ideas, reach out on LinkedIn: Saba Amin
π Version
GoMetaSync v1.0.0 β Initial public release (Schema Drift Detection & Struct Generation)