Skip to content

gdwisnusetiawan/db-migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕊 DB Migrator

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.

How to use

  1. Build/Pull the DB Migrator image. (Installation)
  2. Run the image to the container. (Setup)
  3. Run the available DB Migrator operations from the container. (Operations)

Installation

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 .

Setup (Service Template)

Run the docker compose up command inside the service template to automatically setup the Postgres & DB Migrator container and ready to execute available operations.

Setup (OS Env)

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

Operations

  • 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

Optimizations

  • Handle multiple kind of databases (mysql, mongodb, etc).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages