Sign inSign up

ogulcanaydogan/db-migrate

By ogulcanaydogan

Updated 7 months ago

Database migration runner for PostgreSQL and MySQL

Image
0

1.4K

ogulcanaydogan/db-migrate repository overview

DB Migrate

Simple database migration runner for PostgreSQL and MySQL.

Quick Start

docker run \
  -e DB_TYPE=postgresql \
  -e DB_HOST=localhost \
  -e DB_NAME=myapp \
  -e DB_USER=postgres \
  -e DB_PASSWORD=secret \
  -v $(pwd)/migrations:/migrations \
  ogulcanaydogan/db-migrate up

Commands

CommandDescription
up [VERSION]Apply pending migrations (optionally up to VERSION)
down [STEPS]Roll back migrations (default: 1 step)
statusShow applied and pending migrations
create NAMECreate new migration file pair

Migration File Format

migrations/
├── 001_create_users.up.sql
├── 001_create_users.down.sql
├── 002_add_email_index.up.sql
└── 002_add_email_index.down.sql

Environment Variables

VariableDescriptionDefault
DB_TYPEpostgresql or mysqlpostgresql
DB_HOSTDatabase hostlocalhost
DB_PORTDatabase portAuto-detected
DB_NAMEDatabase name (required)-
DB_USERDatabase user (required)-
DB_PASSWORDDatabase password-
MIGRATIONS_DIRPath to migration files/migrations
DRY_RUNSet to true for dry runfalse

Docker Compose Example

services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret

  migrate:
    image: ogulcanaydogan/db-migrate
    command: ["up"]
    depends_on:
      db:
        condition: service_healthy
    environment:
      - DB_HOST=db
      - DB_NAME=myapp
      - DB_USER=postgres
      - DB_PASSWORD=secret
    volumes:
      - ./migrations:/migrations

License

MIT

Tag summary

Content type

Image

Digest

sha256:8e7fe60e1

Size

74.1 MB

Last updated

7 months ago

docker pull ogulcanaydogan/db-migrate