![a_cool_futuristic_hd_mascot_for_the](https://private-user-images.githubusercontent.com/10183382/378108228-d5f5fce7-afcb-4136-a7a8-a5e8a7e7d7c4.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5Mzc1OTEsIm5iZiI6MTczODkzNzI5MSwicGF0aCI6Ii8xMDE4MzM4Mi8zNzgxMDgyMjgtZDVmNWZjZTctYWZjYi00MTM2LWE3YTgtYTVlOGE3ZTdkN2M0LmpwZWc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxNDA4MTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01ZjAyNWYyYzEyN2VmYmQzMmUzZjZmN2MxODQ0MjFmZDBhMTk2MTk0MTExYWJjOTQyODA1NjQyMjYxMzRhMTk5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9._j7rPSECN9Hql-t1m-JvO0HIfvtp-Eg2-eUgruroBg8)
A command-line tool for applying SQL migrations to a PostgreSQL database using Go and Cobra.
- Applies SQL migration files in order
- Tracks applied migrations to ensure each is run only once
- Configurable via command-line flags
Clone the repository, build the project, and run it:
go build -o migrate
./migrate --dbHost="localhost" --dbPort="5432" --dbUser="postgres" --dbPassword="password" --dbName="mydb" --migrationDir="./migrations" --sslMode="disable"
Flag | Default | Description |
---|---|---|
--dbHost |
localhost |
PostgreSQL host |
--dbPort |
5432 |
PostgreSQL port |
--dbUser |
postgres |
PostgreSQL user |
--dbPassword |
password |
PostgreSQL password |
--dbName |
postgres |
PostgreSQL database name |
--migrationDir |
migrations |
Path to the migration files directory |
--sslMode |
disable |
SSL Mode |
Build the Docker image and run the container:
docker build -t db-migration-tool .
docker run --rm \
-e DB_HOST="localhost" \
-e DB_PORT="5432" \
-e DB_USER="postgres" \
-e DB_PASSWORD="password" \
-e DB_NAME="mydb" \
-v /path/to/migrations:/migrations \
db-migration-tool