{"id":22989317,"url":"https://github.com/olbrichattila/godbmigrator_cmd","last_synced_at":"2026-05-06T04:04:11.135Z","repository":{"id":183526247,"uuid":"670305382","full_name":"olbrichattila/godbmigrator_cmd","owner":"olbrichattila","description":"Golang command line database migrator, and HTTP migrator server, dockerized for CI-CD pipelines","archived":false,"fork":false,"pushed_at":"2025-03-26T08:56:19.000Z","size":8822,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-27T12:02:11.405Z","etag":null,"topics":["automation","ci-cd","database","database-migration","go","golang","golang-application","migration","mysq","postgresql","sqlite"],"latest_commit_sha":null,"homepage":"https://attilaolbrich.co.uk/blog/3/single","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olbrichattila.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-24T18:46:07.000Z","updated_at":"2025-03-26T08:55:27.000Z","dependencies_parsed_at":"2024-05-29T22:56:02.798Z","dependency_job_id":null,"html_url":"https://github.com/olbrichattila/godbmigrator_cmd","commit_stats":null,"previous_names":["olbrichattila/godbmigrator_cmd"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/olbrichattila/godbmigrator_cmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator_cmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator_cmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator_cmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator_cmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olbrichattila","download_url":"https://codeload.github.com/olbrichattila/godbmigrator_cmd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator_cmd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32677933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","ci-cd","database","database-migration","go","golang","golang-application","migration","mysq","postgresql","sqlite"],"created_at":"2024-12-15T04:17:19.652Z","updated_at":"2026-05-06T04:04:11.105Z","avatar_url":"https://github.com/olbrichattila.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang Database Migrator (godbmigrator)  \nA simple and flexible database migration tool for Go applications.\n\n## Create Migration SQL Files\n\n## Installation\n\nTo install as a CLI tool:\n```bash\ngo install github.com/olbrichattila/godbmigrator_cmd/cmd/migrator@latest\n```\n\nIf you'd like to integrate the migration into your application, please refer to:\nhttps://github.com/olbrichattila/godbmigrator/\n\n\n## Migration File Structure\nFollow this structure:\n[id]-migrate-[custom-content].sql\n\nThe files are processed in ascending order, so it's important to prefix them with an ID or timestamp.  \nAlternatively, you can use the following command to generate a properly formatted migration file: ```migrator add \u003coptional suffix\u003e```\n\nFor example:\n```bash\n2024-05-27_19_49_38-migrate.sql\n2024-05-27_19_49_38-rollback.sql\n2024-05-27_19_50_04-migrate.sql\n2024-05-27_19_50_04-rollback.sql\n```\n\n## Command line usage:\nMigrate:\n```bash\nmigrator migrate\n```\n\nRollback:\n```bash\nmigrator rollback\n```\n\nReport:\n```bash\nmigrator report\n```\n\nAdding new migration and rollback file:\n```bash\nmigrator add \u003cyour custom message\u003e\n```\nNote: the custom message is not mandatory, in that case the file will be a standard format, like date_time-migration.sql\n\n\n### Running Migrations and Rollbacks  \n\nYou can apply or roll back a specific number of migrations by passing a number as an argument.\n\n**Migrate the last 2 migrations:**  \n```bash\nmigrator migrate 2\nmigrator rollback 2\n```\n\n\n### Refresh\n(Refresh is when all applied migration is rolled back and migrated up from scratch)\n```bash\nmigrator refresh\n```\n\nHere if the count parameter supplied will be ignored\n\n## Baseline\n\u003e Note: this feature is currently in beta\nYou can create a snapshot of the current database schema and restore it when recreating the database.  \nThis is also useful for generating a test database from a production database without copying data.\nPlease note: this supports only SQLite, MySql and PostgreSQL. (firebird support coming later)\n\nUsage:\n```bash\nmigrator save-baseline\nmigrator restore-baseline\n```\n\n### When building the application.\n```bash\nmake install\n```\nThe build folder will contain the migrator executable.\n\nUsage is the same but using the application:\n\n```bash\nmigrator migrate\nmigrator rollback\nmigrator migrate 2\nmigrator migrate 2 -force\nmigrator rollback 2\nmigrator refresh\nmigrator report\nmigrator validate\nmigrator save-baseline\nmigrator restore-baseline\nmigrator add \u003coptional migration file suffix\u003e\nhelp (for full detailed help)\n```\n\n### Available flags:\n```-force``` This flag will skip checksum verification\n\nThe number of rollbacks and migrates are not mandatory.\nIf it is set, for rollbacks it only apply for the last rollback batch\nValidate checks if any migration file changed since last applied\n\n## Configuring Database Connections\n\n### **Using Environment Variables**\nIf no `.env.migrator` file is present, the application will read environment variables from the operating system.\n\n#### **Example (Linux/macOS Terminal)**\n```bash\nexport DB_CONNECTION=sqlite\nexport DB_DATABASE=./data/database.sqlite\n```\n\nUnset the variables can be done:\n```bash\nunset DB_CONNECTION\nunset DB_DATABASE\n```\n\n### Create a .env file into your root directory\nExamples:\nNote: ```TABLE_PREFIX``` is non mandatory, if not set, the migration table prefix will be ```olb``` (example ```olb_migrations```, ```olb_migration_reports```)\n\n### sqlite\n```bash\nDB_CONNECTION=sqlite  \nDB_DATABASE=./data/database.sqlite  \nTABLE_PREFIX=\"my_prefix\"  # (Optional: Defaults to \"olb_\")\n```\n\n### MySql\n```bash\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=migrator\nDB_USERNAME=root\nDB_PASSWORD=password\nTABLE_PREFIX=\"my_prefix\"\n```\n\n### Postgres\n```bash\nDB_CONNECTION=pgsql\nDB_HOST=127.0.0.1\nDB_PORT=5432\nDB_DATABASE=postgres\nDB_USERNAME=postgres\nDB_PASSWORD=postgres\nTABLE_PREFIX=\"my_prefix\"\n\n# non mandatory, it defaults to disable\n# possible values are: disable, require, verify-ca, verify-full, prefer, allow (depending on your setup)\nDB_SSLMODE=disable\n```\n\n### Firebird / Interbase\n```bash\nDB_CONNECTION=firebird\nDB_HOST=127.0.0.1\nDB_PORT=3050\nDB_DATABASE=/opt/firebird/examples/empbuild/employee.fdb\nDB_USERNAME=SYSDBA\nDB_PASSWORD=masterkey\nTABLE_PREFIX=\"my_prefix\"\n\nMIGRATOR_MIGRATION_PATH=./migrations/firebird\n```\n\n## Setting migration path\nThe path by default is ./migrations\nThis can be overwritten by adding the followin variable to your .env file\n```bash\nMIGRATOR_MIGRATION_PATH=./migrations/custom_path\n```\n\n## HTTP Server Mode\nSet the server port. If not defined, it will default to **8080**.\n```bash\nHTTP_SERVER_PORT=8081\n```\n\n## Available make targets:\n```bash\nmake migrate\nmake rollback\nmake refresh\nmake install\nmake report\n```\n## Switch .env file with boilerplate setup for the followin database connections\n```bash\nmake switch-sqlite\nmake switch-mysql\nmake switch-pgsql\nmake switch-firebird\n```\n\n## Test locally\n### 1. Docker setup:\n\n```bash\n# Create your docker containers with docker-compose, MySql, FireBird and Postgresql images will be creted exposing the default ports, Change it if required.\ncd docker\ndocker-compose up -d\n```\n\nSwitch to your testable database with the above make switc-\u003cdbengine\u003e command.\n\nCheck your .env file for migration path:\n\n```bash\nMIGRATOR_MIGRATION_PATH=./migrations/new\n```\n\nand create a folder if not exists:\n```bash\nmkdir -p ./migrations/new\n```\n\n#### Add your migrations:\n```bash\nmigrator add \u003coptionally a file name suffix\u003e\n```\n\nFill in your migration and rollback file you created, then try migrate, rollback, (with number parameters) and report as explained above\n\n---\n\n## HTTP Server\nTo run the migrator locally, use:\n```bash\nmigrator serve\n```\n\n### URL Parameters\n\nThe following URL parameters can be used:\n- **command** – The migration command (e.g., migrate, rollback).\n- **count** (optional) – Number of items to migrate or rollback.\n- **force** (optional) – Accepts 0, 1, false, or true. Forces migration even if integrity validation fails.\n\n**Example Requests**\n```bash\nhttp://localhost:8081?command=migrate\u0026count=2\u0026force=true\nhttp://localhost:8081?command=add\u0026name=add_users\n```\n\n---\n\n## Pre-Built Docker Image\n**Pull the Image**\n```bash\ndocker pull aolb/migrator\n```\n**Run with Environment Variables**\n```bash\ndocker run -e HTTP_SERVER_PORT=8080 -e DB_CONNECTION=sqlite -e DB_DATABASE=./database.sqlite -e MIGRATOR_MIGRATION_PATH=./ -p8080:8080 aolb/migrator\n```\n\n**Example docker compose**\n```yml\nversion: \"3.8\"\n\nservices:\n  migrator:\n    image: aolb/migrator:latest\n    build: .\n    ports:\n      - \"8081:8080\"\n    environment:\n      - HTTP_SERVER_PORT=8080\n      - DB_CONNECTION=sqlite\n      - DB_DATABASE=./database.sqlite\n      - MIGRATOR_MIGRATION_PATH=./\n    restart: unless-stopped\n```\n\n---\n\n## About me:\n- Learn more about me on my personal website: https://attilaolbrich.co.uk/menu/my-story\n- Check out my latest blog post on my website: https://attilaolbrich.co.uk/blog/1/single\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folbrichattila%2Fgodbmigrator_cmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folbrichattila%2Fgodbmigrator_cmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folbrichattila%2Fgodbmigrator_cmd/lists"}