
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