{"id":28311320,"url":"https://github.com/alonmell/migrator","last_synced_at":"2026-06-25T02:31:36.936Z","repository":{"id":256748159,"uuid":"856307606","full_name":"AlonMell/migrator","owner":"AlonMell","description":"A lightweight, transaction-safe SQL migration tool for Go applications featuring version-based tracking, bidirectional migrations, and detailed logging.","archived":false,"fork":false,"pushed_at":"2025-04-12T11:59:51.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-22T06:35:18.249Z","etag":null,"topics":["database-migrations","golang","sql","transactions","versioning"],"latest_commit_sha":null,"homepage":"","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/AlonMell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2024-09-12T11:04:57.000Z","updated_at":"2025-04-12T11:58:52.000Z","dependencies_parsed_at":"2025-06-22T06:41:16.510Z","dependency_job_id":null,"html_url":"https://github.com/AlonMell/migrator","commit_stats":null,"previous_names":["alonmell/migrator"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/AlonMell/migrator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlonMell%2Fmigrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlonMell%2Fmigrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlonMell%2Fmigrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlonMell%2Fmigrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlonMell","download_url":"https://codeload.github.com/AlonMell/migrator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlonMell%2Fmigrator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283095890,"owners_count":26778518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-06T02:00:06.180Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["database-migrations","golang","sql","transactions","versioning"],"created_at":"2025-05-24T12:11:06.224Z","updated_at":"2025-11-06T23:03:09.616Z","avatar_url":"https://github.com/AlonMell.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Migrator\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/AlonMell/migrator.svg)](https://pkg.go.dev/github.com/AlonMell/migrator)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/AlonMell/migrator)](https://github.com/AlonMell/migrator)\n[![License](https://img.shields.io/github/license/AlonMell/migrator)](https://github.com/AlonMell/migrator/blob/main/LICENSE)\n\nA lightweight, SQL-based database migration tool for Go applications.\n\n## Features\n\n- Simple and efficient SQL migration management\n- Supports both UP and DOWN migrations\n- Version-based migration tracking\n- Transaction-based migrations for safety\n- Detailed logging with customizable log levels\n- Automatic migration table creation\n- Compatible with PostgreSQL (extensible for other databases)\n\n## Installation\n\n```bash\ngo get github.com/AlonMell/migrator\n```\n\n## Usage\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"log\"\n\n\t\"github.com/AlonMell/migrator\"\n\t_ \"github.com/lib/pq\"\n)\n\nfunc main() {\n\t// Connect to the database\n\tdb, err := sql.Open(\"postgres\", \"postgres://user:password@localhost:5432/dbname?sslmode=disable\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to connect to database: %v\", err)\n\t}\n\tdefer db.Close()\n\n\t// Create a new migrator\n\t// Parameters: database connection, logger, major version, minor version,\n\t// migrations table name, migrations directory path\n\tm := migrator.New(db, nil, 1, 0, \"migrations\", \"./migrations\")\n\n\t// Run migrations\n\tctx := context.Background()\n\tif err := m.Migrate(ctx); err != nil {\n\t\tlog.Fatalf(\"Migration failed: %v\", err)\n\t}\n}\n```\n\n### With Custom Logger\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"log/slog\"\n\t\"os\"\n\n\t\"github.com/AlonMell/grovelog\"\n\t\"github.com/AlonMell/migrator\"\n\t_ \"github.com/lib/pq\"\n)\n\nfunc main() {\n\t// Setup logger\n\topts := grovelog.NewOptions(slog.LevelDebug, \"\", grovelog.Color)\n\tlogger := grovelog.NewLogger(os.Stdout, opts)\n\n\t// Connect to database\n\tdb, err := sql.Open(\"postgres\", \"postgres://user:password@localhost:5432/dbname?sslmode=disable\")\n\tif err != nil {\n\t\tlogger.Error(\"Failed to connect to database\", err)\n\t\tos.Exit(1)\n\t}\n\tdefer db.Close()\n\n\t// Create migrator with custom logger\n\tm := migrator.New(db, logger, 1, 0, \"migrations\", \"./migrations\")\n\n\t// Run migrations\n\tctx := context.Background()\n\tif err := m.Migrate(ctx); err != nil {\n\t\tlogger.Error(\"Migration failed\", err)\n\t\tos.Exit(1)\n\t}\n}\n```\n\n## Migration File Format\n\nMigration files must follow this naming convention:\n\n```\nnnnn.mm.nn[.comment].(up|down).sql\n```\n\nWhere:\n- `nnnn` - File number (4 digits)\n- `mm` - Major version (2 digits)\n- `nn` - Minor version (2 digits)\n- `[.comment]` - Optional comment/description\n- `(up|down)` - Migration direction (up = apply, down = rollback)\n\nExamples:\n- `0001.00.00.baseline.up.sql` - Initial schema creation\n- `0001.00.00.baseline.down.sql` - Rollback for initial schema\n- `0002.00.01.create_users.up.sql` - Create users table\n- `0002.00.01.create_users.down.sql` - Drop users table\n\n## Version Control\n\nThe migrator uses a version system with major and minor components:\n- Major version (mm) - For significant schema changes\n- Minor version (nn) - For smaller, incremental changes\n\nWhen running the migrator, specify the target version (major.minor) you want to migrate to:\n- To upgrade: specify a higher version than current\n- To downgrade: specify a lower version than current\n\n## Development\n\n### Requirements\n\n- Go 1.24+\n- PostgreSQL\n- Docker (for integration tests)\n\n### Testing\n\nRun integration tests with Docker:\n```bash\nmake test\n```\n\n### Building\n\n```bash\nmake build\n```\n\n### Other Commands\n\n```bash\nmake help  # Show available commands\n```\n\n## License\n\nMIT License - See LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falonmell%2Fmigrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falonmell%2Fmigrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falonmell%2Fmigrator/lists"}