{"id":21461153,"url":"https://github.com/olbrichattila/godbmigrator","last_synced_at":"2026-04-18T13:34:39.108Z","repository":{"id":183063275,"uuid":"669543765","full_name":"olbrichattila/godbmigrator","owner":"olbrichattila","description":"Golang database migration","archived":false,"fork":false,"pushed_at":"2025-03-25T19:17:09.000Z","size":131,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-12T14:51:24.426Z","etag":null,"topics":["go","golang","golang-library","golang-package","migration","migration-tool","mysql","postgresql","sqlite","sqlite3"],"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/olbrichattila.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-07-22T16:10:58.000Z","updated_at":"2025-03-25T19:16:53.000Z","dependencies_parsed_at":"2024-05-29T21:34:42.954Z","dependency_job_id":null,"html_url":"https://github.com/olbrichattila/godbmigrator","commit_stats":null,"previous_names":["olbrichattila/go-database-migrator","olbrichattila/godbmigrator"],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/olbrichattila/godbmigrator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olbrichattila","download_url":"https://codeload.github.com/olbrichattila/godbmigrator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olbrichattila%2Fgodbmigrator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31971488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["go","golang","golang-library","golang-package","migration","migration-tool","mysql","postgresql","sqlite","sqlite3"],"created_at":"2024-11-23T07:07:45.604Z","updated_at":"2026-04-18T13:34:39.064Z","avatar_url":"https://github.com/olbrichattila.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang Database Migrator\n\nThis package is designed to add database migration functionality to your project. It is not intended to be used independently.\nIf you would like to use it as a command-line tool, please use it with the command-line wrapper available here:\n\nhttps://github.com/olbrichattila/godbmigrator_cmd\n\nThis package is lightweight and does not include any database drivers.\nYou can create migration SQL files in a designated folder.\n\n---\n\n## Migration File Structure\nFollow this naming convention for migration files:\n[date-time]-migrate-[custom-content].sql\n\nFiles will be processed in ascending order, so it's important to create a unique identifier, such as a timestamp.\n\n--- \n\n### Example:\n```\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```\nThis ensures that migrations are executed in the correct sequence.\n\n---\n\n### Adding to Your Code\n#### Import the module:\n\n```\nmigrator \"github.com/olbrichattila/godbmigrator\"\n```\n#### Requirements\nYou need to have:\n- A database connection (*sql.DB)\n- Migration table prefix, or it can be empty string as well\n\n\n### Table Prefix\nThe prefix parameter sets a database table prefix. If you set it to xyz, the migration table will be named xyz_migration to store applied migrations.\n\n---\n\n### Migration Operations\n#### Example: Running Migrations\n```\nmigrationFilePath := \"./migration\"\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.Migrate(count)\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n#### Example: Rolling Back Migrations\n```\nmigrationFilePath := \"./migration\"\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.Rollback(count)\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n#### Example: Refreshing Migrations\nA refresh rolls back all migrations and applies them from scratch.\n```\nmigrationFilePath := \"./migration\"\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.Refresh()\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n#### Example: Creating a New Migration File\n```\nmigrationFilePath := \"./migration\"\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.AddNewMigrationFiles(\"custom-text-or-empty\")\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n\n---\n\n### Checksum Validator\nYou can validate whether any migration file has changed since it was applied.\n```\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.Migrate(3)\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n\nerrors := m.ChecksumValidation(db, tablePrefix, testChecksumFixtureFolder)\n// 'errors' contains a list of error strings ([]string). If empty, there are no validation errors.\n```\n\n---\n### Baseline Operations\n#### Create a Baseline of Your Existing Database Structure\n```\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.SaveBaseline()\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n#### Restore Baseline\n```\nm := migrator.New(db, \"prefix\", migrationFilePath)\nerr := m.LoadBaseline()\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n```\n\n---\n\n### Migration Report\nThe application stores a migration audit report, where you can track applied migrations, rollbacks, and any errors encountered during migration.\n#### Fetching the migration report as a readable string:\n```\nmigrationFilePath := \"./migration\"\nm := migrator.New(db, \"prefix\", migrationFilePath)\nreport, err := m.Report()\nif err != nil {\n    panic(\"Error: \" + err.Error())\n}\n\nfmt.Println(report)\n```\n\n---\n\n## Subscribing to Messages:\n\nYou can subscribe to messages using a callback function. When a message is received, the callback ```func(int, string)``` will be invoked with the message type ID and an optional message text.\n\n### Example\n```\nm := migrator.New(db, \"prefix\", migrationFilePath)\nm.SubscribeToMessages(func(et int, msg string) {\n    fmt.Println(et, msg)\n})\n```\n\n---\n\n### Available Make Targets\nYou can use make commands for quick setup and testing:\n```\nmake run\nmake install\nmake run-test\n```\n\n---\n### Supported Database Drivers\n- SQLite\n- MySQL\n- PostgreSQL\n- Firebird / InterBase (except for baseline operations)\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 blog at my personal page. https://attilaolbrich.co.uk/blog/1/single\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folbrichattila%2Fgodbmigrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folbrichattila%2Fgodbmigrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folbrichattila%2Fgodbmigrator/lists"}