{"id":50884327,"url":"https://github.com/j4flmao/go-migrate-safe","last_synced_at":"2026-06-15T15:32:38.297Z","repository":{"id":362176202,"uuid":"1232871447","full_name":"j4flmao/go-migrate-safe","owner":"j4flmao","description":"A safe, schema-first database migration tool for Go with support for PostgreSQL, MySQL, SQLite, SQL Server, and MongoDB","archived":false,"fork":false,"pushed_at":"2026-06-03T01:18:36.000Z","size":284,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T03:14:49.860Z","etag":null,"topics":["database","golang","migration"],"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/j4flmao.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2026-05-08T11:07:16.000Z","updated_at":"2026-05-10T08:04:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/j4flmao/go-migrate-safe","commit_stats":null,"previous_names":["j4flmao/go-migrate-safe"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/j4flmao/go-migrate-safe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j4flmao%2Fgo-migrate-safe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j4flmao%2Fgo-migrate-safe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j4flmao%2Fgo-migrate-safe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j4flmao%2Fgo-migrate-safe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j4flmao","download_url":"https://codeload.github.com/j4flmao/go-migrate-safe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j4flmao%2Fgo-migrate-safe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34369842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"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","golang","migration"],"created_at":"2026-06-15T15:32:37.324Z","updated_at":"2026-06-15T15:32:38.277Z","avatar_url":"https://github.com/j4flmao.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-migrate-safe\n\nType-safe database migration library for Go — with auto struct-diff, dry-run, conflict detection, and rollback planning.\n\n## Features\n\n- **Struct-first migrations**: Your Go types are the source of truth\n- **Auto-generated SQL**: No manual SQL writing for common changes\n- **Database agnostic**: Supports PostgreSQL, MySQL, SQLite, SQL Server, and MongoDB\n- **Safety by default**: Destructive operations require explicit opt-in\n- **Rollback planning**: Every migration includes a rollback plan\n- **Dry run mode**: Test migrations before applying to production\n- **GMS Studio**: Built-in modern web UI for database browsing and management (CRUD)\n\n## Installation\n\nInstall the CLI:\n```bash\ngo install github.com/j4flmao/go-migrate-safe/cmd/gms@latest\n```\n\nAdd as a dependency to your project:\n```bash\ngo get github.com/j4flmao/go-migrate-safe\n```\n\n## Quick Start\n\n### 1. Define your models\n\n```go\npackage models\n\nimport \"time\"\n\ntype User struct {\n\tID        int64     `db:\"id,pk,autoincrement\"`\n\tEmail     string    `db:\"email,unique,not null\"`\n\tPassword  string    `db:\"password,not null\"`\n\tCreatedAt time.Time `db:\"created_at,not null,default:now()\"`\n}\n\ntype Product struct {\n\tID          int64   `db:\"id,pk,autoincrement\"`\n\tName        string  `db:\"name,not null\"`\n\tDescription string  `db:\"description,not null\"`\n\tPrice       float64 `db:\"price,not null\"`\n}\n```\n\n### 2. Create a migration wrapper\n\nCreate `cmd/gms/main.go` in your project:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/j4flmao/go-migrate-safe/migrate\"\n\t\"github.com/j4flmao/go-migrate-safe/orchestrator\"\n\t_ \"github.com/lib/pq\"\n\t// Import your models package\n\t\"github.com/yourusername/yourproject/models\"\n)\n\nfunc main() {\n\tdsn := os.Getenv(\"DATABASE_URL\")\n\tif dsn == \"\" {\n\t\tlog.Fatal(\"DATABASE_URL is required\")\n\t}\n\n\tdb, err := sql.Open(\"postgres\", dsn)\n\tif err != nil {\n\t\tlog.Fatalf(\"db: %v\", err)\n\t}\n\tdefer db.Close()\n\n\tm, err := migrate.New(\n\t\tmigrate.WithModels(models.User{}, models.Product{}),\n\t\tmigrate.WithOutputDir(\"./migrations\"),\n\t\tmigrate.WithDriver(\"postgres\"),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"migrate: %v\", err)\n\t}\n\n\tintent := os.Args[1]\n\tres, err := orchestrator.Run(context.Background(), intent, orchestrator.Options{\n\t\tMigrator:    m,\n\t\tOutputDir:   \"./migrations\",\n\t\tDialectName: \"postgres\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"%s: %v\", intent, err)\n\t}\n}\n```\n\n### 3. Generate migrations\n\n```bash\n# Set database connection\nexport DATABASE_URL=\"postgres://user:pass@localhost/dbname\"\n\n# Generate migration\ngo run ./cmd/gms generate\n```\n\n### 4. Apply migrations\n\n```bash\n# Check status\ngms status\n\n# Apply pending migrations\ngms apply\n\n# Rollback last migration\ngms rollback\n```\n\n## CLI Commands\n\n| Command      | Description                                      |\n|--------------|--------------------------------------------------|\n| `generate`   | Generate migration files from struct models      |\n| `apply`      | Apply pending migrations                         |\n| `status`     | Show current migration status                    |\n| `history`    | Show migration history                           |\n| `validate`   | Validate all migration files                     |\n| `rollback`   | Rollback last N migrations                       |\n| `diff`       | Show what would change (no files written)        |\n| `studio`     | Launch the GMS Studio web UI to browse/edit DB   |\n\n## GMS Studio\n\nGMS Studio is a built-in web-based database explorer (inspired by Prisma Studio) that allows you to browse tables, view data, and perform CRUD operations directly from your browser.\n\nTo launch it:\n```bash\n# It will auto-detect your DATABASE_URL\ngms studio\n\n# Or specify a driver and address\ngms studio --driver postgres --addr 127.0.0.1:4489\n```\n\nFeatures:\n- **Modern Dark UI**: Clean and responsive interface.\n- **CRUD Operations**: Add, edit, and delete records with a custom confirmation modal.\n- **Schema Awareness**: Automatically detects primary keys and data types for safe editing.\n- **Smart Paging**: Efficiently handle large tables with pagination and search.\n\n## Supported Databases\n\n- PostgreSQL\n- MySQL\n- SQLite\n- SQL Server\n- MongoDB\n\n## Struct Tags\n\n| Tag Option     | Description                                      |\n|----------------|--------------------------------------------------|\n| `pk`           | Mark as primary key                              |\n| `autoincrement`| Auto-incrementing primary key                    |\n| `unique`       | Unique constraint                                |\n| `index`        | Create index                                     |\n| `not null`     | Not null constraint                              |\n| `nullable`     | Nullable field                                   |\n| `default:X`    | Default value                                    |\n| `size:N`       | Column size (for VARCHAR, etc.)                  |\n| `type:T`       | Override SQL type                                |\n| `ignore`       | Ignore this field                                |\n\n## Configuration\n\n### Environment Variables\n\n| Variable         | Description                                      |\n|------------------|--------------------------------------------------|\n| `DATABASE_URL`   | Database connection string                       |\n| `MYSQL_DSN`      | MySQL DSN override                               |\n| `PGSQL_DSN`      | PostgreSQL DSN override                          |\n| `SQLITE_PATH`    | SQLite file path override                        |\n| `MSSQL_DSN`      | SQL Server DSN override                          |\n| `MONGODB_URI`    | MongoDB URI override                              |\n\n### Safety Options\n\nBy default, destructive operations are blocked:\n```go\nm, err := migrate.New(\n    migrate.WithModels(models...),\n    migrate.WithAllowDropTable(),     // Allow DROP TABLE\n    migrate.WithAllowDropColumn(),    // Allow DROP COLUMN\n    migrate.WithAllowTypeChange(migrate.TypeChangeSafe), // Allow safe type changes\n)\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.\n\n## License\n\nMIT License - see [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4flmao%2Fgo-migrate-safe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj4flmao%2Fgo-migrate-safe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj4flmao%2Fgo-migrate-safe/lists"}