A simple tool to migrate a service database. DB Migrator supports YAML or OS Env config type. This tool will be used for the McEasy Platform service template. Make sure you have the same service configuration as the service template.
- Build/Pull the DB Migrator image. (Installation)
- Run the image to the container. (Setup)
- Run the available DB Migrator operations from the container. (Operations)
Make sure you have a Docker & Git installed on your machine.
Clone the repository
# Via HTTPS
git clone https://github.com/mceasy-id/db-migrator.git
# or Via SSH
git clone [email protected]:mceasy-id/db-migrator.git
Go to the db-migrator directory
cd db-migrator
Build the Docker image
docker build -t hub.mceasy.com/db-migrator:v1.0 .
Run the docker compose up
command inside the service template to automatically setup the Postgres & DB Migrator container and ready to execute available operations.
If you want to use the OS Env as the configuration, you have to manually run the image with env (CONFIG_TYPE
,PG_HOST
,PG_PORT
,PG_USER
,PG_PASSWORD
,PG_DBNAME
).
You also have to volume the schema.py
file & versions
folder to the container.
docker run --name db-migrator \
-e CONFIG_TYPE=env \
-e PG_HOST=host \
-e PG_PORT=port \
-e PG_USER=user \
-e PG_PASSWORD=password \
-e PG_DBNAME=dbname \
-v {your project migration version folder path}:/app/alembic/versions
-v {your project migration schema.py path}:/app/schema.py
-it -d migrator
- Create a Revision
docker exec db-migrator alembic revision --autogenerate -m "{custom message}"
- Upgrade the database
docker exec db-migrator alembic upgrade head
- Downgrade the database
docker exec db-migrator alembic downgrade -1
- Handle multiple kind of databases (mysql, mongodb, etc).