{"id":34778878,"url":"https://github.com/gookit/miglite","last_synced_at":"2026-01-30T17:06:20.026Z","repository":{"id":323602134,"uuid":"1091463421","full_name":"gookit/miglite","owner":"gookit","description":"miglite is a simplified database schema migration tool. Golang 实现的极简的数据库 Schema 迁移工具，无三方DB驱动依赖。","archived":false,"fork":false,"pushed_at":"2026-01-28T05:16:46.000Z","size":513,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-28T18:23:26.910Z","etag":null,"topics":["migration","migration-tool","migrations"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/gookit/miglite","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/gookit.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":"2025-11-07T03:44:45.000Z","updated_at":"2026-01-28T15:11:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gookit/miglite","commit_stats":null,"previous_names":["gookit/miglite"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/gookit/miglite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fmiglite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fmiglite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fmiglite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fmiglite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gookit","download_url":"https://codeload.github.com/gookit/miglite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gookit%2Fmiglite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28915942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T16:37:38.804Z","status":"ssl_error","status_checked_at":"2026-01-30T16:37:37.878Z","response_time":66,"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":["migration","migration-tool","migrations"],"created_at":"2025-12-25T08:44:59.791Z","updated_at":"2026-01-30T17:06:20.013Z","avatar_url":"https://github.com/gookit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# miglite - Lite database schema migration tool by Go\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gookit/miglite?style=flat-square)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/miglite)](https://github.com/gookit/miglite)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/miglite)](https://goreportcard.com/report/github.com/gookit/miglite)\n[![Unit-Tests](https://github.com/gookit/miglite/workflows/Unit-Tests/badge.svg)](https://github.com/gookit/miglite/actions)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/miglite.svg)](https://pkg.go.dev/github.com/gookit/miglite)\n\n\u003e **👉 [中文说明](README.zh-CN.md)**\n\n`miglite` is a minimalist database schema migration tool implemented in Golang.\n\n- Easy to use with minimal dependencies\n- Developed based on `database/sql` without adding any driver dependencies by default\n- Migration SQL is executed within transactions to ensure data consistency\n- Uses raw SQL files as migration files\n  - SQL filename format: `YYYYMMDD-HHMMSS-{migration-name}.sql`\n- By default, all SQL files (including subdirectories) in the migration directory are recursively searched \n  - Directories starting with `_` (eg. `_backup/xx.sql`) are ignored when looking for SQL files \n  - Migration directories support the use of environment variables (eg `.migrations/${MODULE_NAME}`)}) \n  - Migration directories support adding multiple paths using comma `,` splitting\n- Can run migrations with zero configuration via environment variables (e.g., `DATABASE_URL`, `MIGRATIONS_PATH`)\n  - Automatically attempts to load `.env` file in the directory(Optional)\n  - Automatically loads default configuration file `./miglite.yaml`(Optional)\n- Supports `mysql`, `sqlite`, `postgres` databases\n  - When used as a library, you need to add your own DB driver dependencies\n  - When using the `miglite` command-line tool directly, driver dependencies are already included\n\n## Installation\n\nUsing the `miglite` command-line tool:\n\n```bash\n# install it by go\ngo install github.com/gookit/miglite/cmd/miglite@latest\n```\n\nUsing as a Go dependency library:\n\n```bash\ngo get github.com/gookit/miglite\n\n# import \"github.com/gookit/miglite\"\n```\n\n## Direct CLI Usage\n\nUsing the `miglite` command-line tool directly.\n\n![help](./testdata/help.png)\n\n### Configuration\n\n`miglite` supports configuration via `miglite.yaml` file or environment variables.\n\n- Can work without a configuration file, using the environment variable `DATABASE_URL` directly\n- Configuration file defaults to `./miglite.yaml`, but can be specified via the `--config` parameter\n\n#### miglite.yaml Example\n\n```yaml\ndatabase:\n  driver: sqlite  # or mysql, postgresql\n  dsn: ./miglite.db  # or connection string for other databases\nmigrations:\n  path: ./migrations\n```\n\n#### Environment Variables\n\n- `DATABASE_URL`: Database connection URL (e.g., `sqlite://path/to/your.db`, `mysql://user:pass@tcp(host:port)/dbname`)\n- `MIGRATIONS_PATH`: Migration files path (default: `./migrations`)\n\n**Examples**:\n\n```ini\nMIGRATIONS_PATH = \"./migrations\"\n# sqlite\nDATABASE_URL=\"sqlite://path/to/your.db\"\n# mysql\nDATABASE_URL=\"mysql://user:passwd@tcp(127.0.0.1:3306)/local_test?charset=utf8mb4\u0026parseTime=True\u0026loc=Local\"\n# postgresql\nDATABASE_URL=\"postgres://host=localhost port=5432 user=username password=password dbname=dbname sslmode=disable\"\n```\n\n\u003e **NOTE**: mysql URLs must be tagged with the 'tcp' protocol\n\n### Creating Migrations\n\n```bash\nmiglite create add-users-table\n```\n\nThis will create an SQL file named with the current date in the `./migrations/` directory, with the format `YYYYMMDD-HHMMSS-add-users-table.sql`.\n\n```text\n./migrations/20251105-102325-create-users-table.sql\n```\n\nSQL file content includes a template:\n\n```sql\n-- Migrate:UP\n-- Add migration SQL here\n\n-- Migrate:DOWN\n-- Add rollback SQL here (optional)\n```\n\nExample migration file:\n\n```sql\n-- Migrate:UP\nCREATE TABLE post (\n  id int NOT NULL,\n  title text,\n  body text,\n  PRIMARY KEY(id)\n);\n\n-- Migrate:DOWN\nDROP TABLE post;\n```\n\n### Running Migrations\n\n```bash\n# Initialize the migrations schema table\nmiglite init\n\n# Apply all pending migrations\nmiglite up\n# Execute immediately without confirmation\nmiglite up --yes\n\n# Rollback the most recent migration\nmiglite down\n# Rollback multiple migrations\nmiglite down --number 3\n\n# View migration status\nmiglite status\n```\n\nView migration status:\n\n![status](./testdata/status.png)\n\n## Using as a Library\n\n`miglite` **does not depend on** any third-party DB driver libraries by itself, so you can use it as a library with your current database driver library.\n\n- Sqlite drivers:\n  - `modernc.org/sqlite` **CGO-free driver**\n  - `github.com/glebarez/go-sqlite`  Based on `modernc.org/sqlite`\n  - `github.com/ncruces/go-sqlite3` **CGO-free** Based on Wasm(wazero)\n  - `github.com/mattn/go-sqlite3`  **NEED cgo**\n- MySQL driver:\n  - `github.com/go-sql-driver/mysql`\n- Postgres driver:\n  - `github.com/lib/pq`\n  - `github.com/jackc/pgx/v5`\n- MSSQL driver:\n  - `github.com/microsoft/go-mssqldb`\n\n\u003e More drivers see: https://go.dev/wiki/SQLDrivers\n\n```go\npackage main\n\nimport (\n  \"github.com/gookit/miglite\"\n\n  // add your database driver\n  _ \"github.com/go-sql-driver/mysql\"\n  // _ \"github.com/lib/pq\"\n  // _ \"modernc.org/sqlite\"\n)\n\nfunc main() {\n  mig, err := miglite.NewAuto(func(cfg *config.Config) {\n    // update config options\n  })\n  goutil.PanicIfErr(err) // handle error\n\n  // run up migrations\n  err = mig.Up(command.UpOption{\n    Yes: true, // dont confirm\n    // ... options\n  })\n  goutil.PanicIfErr(err) // handle error\n\n  // run down migrations ...\n}\n```\n\n### Building Your Own Command Tool\n\nYou can directly use the `miglite` library to quickly build your own migration command tool, allowing you to register only the database drivers you need.\n\n```go\npackage main\n\nimport (\n\t\"github.com/gookit/miglite\"\n\t\"github.com/gookit/miglite/pkg/command\"\n\n\t// add your database driver\n\t_ \"github.com/go-sql-driver/mysql\"\n\t// _ \"github.com/lib/pq\"\n\t// _ \"modernc.org/sqlite\"\n)\n\nvar Version = \"0.1.0\"\n\nfunc main() {\n\t// Optional: Information needs to be specified at build time via ldflags\n\t// command.SetBuildInfo(Version, GoVersion, BuildTime, GitCommit)\n\n\t// Create the CLI application\n\tapp := command.NewApp(\"miglite\", Version, \"Lite database schema migration tool by Go\")\n\n\t// Run the application\n\tapp.Run()\n}\n```\n\n\u003e **NOTE**: If you want to further customize the CLI application, you can freely choose other CLI libraries, parse options, and then call the `handleXXX()` methods under `command` to execute the logic.\n\n## Related Projects\n\n- [golang-migrate](https://github.com/golang-migrate/migrate)\n- [pressly/goose](https://github.com/pressly/goose)\n- [amacneil/dbmate](https://github.com/amacneil/dbmate)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fmiglite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgookit%2Fmiglite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgookit%2Fmiglite/lists"}