{"id":28350175,"url":"https://github.com/nissy/mg","last_synced_at":"2025-10-06T01:59:23.132Z","repository":{"id":37751217,"uuid":"190264365","full_name":"nissy/mg","owner":"nissy","description":"mg is database migrations command.","archived":false,"fork":false,"pushed_at":"2020-09-03T09:01:30.000Z","size":79,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-22T08:43:50.754Z","etag":null,"topics":["database","migrations","mysql","postgres"],"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/nissy.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}},"created_at":"2019-06-04T19:13:50.000Z","updated_at":"2022-07-21T03:37:14.000Z","dependencies_parsed_at":"2022-08-08T21:31:01.766Z","dependency_job_id":null,"html_url":"https://github.com/nissy/mg","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/nissy/mg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy%2Fmg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy%2Fmg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy%2Fmg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy%2Fmg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nissy","download_url":"https://codeload.github.com/nissy/mg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nissy%2Fmg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278547821,"owners_count":26004775,"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-10-05T02:00:06.059Z","response_time":54,"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","mysql","postgres"],"created_at":"2025-05-27T21:10:54.307Z","updated_at":"2025-10-06T01:59:23.127Z","avatar_url":"https://github.com/nissy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mg\nmg is database migrations command.\n\nsupport databases\n- PostgreSQL\n- MySQL\n\n### install\n\n```bash\n$ go get -u github.com/nissy/mg/cmd/mg\n```\n\nMac OS X\n```bash\n$ brew tap nissy/mg\n$ brew install nissy/mg/mg\n```\n\n### config\n\n- default config read is `mg.toml` in current directory\n- environment variable support\n\n```toml\n[postgres-sample]\n  driver = \"postgres\"\n  dsn = \"postgres://user:password@127.0.0.1:5432/dbname?sslmode=disable\"\n  source_dir = [\n    \"./testdata/postgres/migrates\",\n    \"./testdata/postgres/seeds\"\n  ]\n\n[mysql-sample]\n  driver = \"mysql\"\n  dsn = \"user:password@tcp(127.0.0.1:3306)/dbname\"\n  source_dir = [\n    \"./testdata/mysql/migrates\",\n    \"./testdata/mysql/seeds\"\n  ]\n\n[environment-variable-sample]\n  driver = \"postgres\"\n  dsn = \"postgres://user:${PASSWORD}@${HOSTNAME}:5432/dbname?sslmode=disable\"\n  source_dir = [\n    \"./testdata/postgres/migrates\",\n    \"./testdata/postgres/seeds\"\n  ]\n```\n\noptions\n\n```toml\n[option-sample] # section name\n  driver = \"postgres\" # database driver\n  dsn = \"postgres://user:${PASSWORD}@${HOSTNAME}:5432/dbname?sslmode=disable\" # database dsn\n  source_dir = [ # database source directorys\n    \"./testdata/postgres/migrates\",\n    \"./testdata/postgres/seeds\"\n  ]\n  up_annotation = \"+goose Up\" # database up command annotation\n  down_annotation = \"+goose Down\" # database down command annotation\n  version_table = \"migration_versions\" # versions use table name\n  version_start_number = 2019060819341936 # version start number\n  json_format = true # output message format\n```\n\n\n### source sql\n\n```sql\n-- @migrate.up\nCREATE TABLE users (\n  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n  created_at datetime DEFAULT NULL,\n  updated_at datetime DEFAULT NULL,\n  PRIMARY KEY (id)\n) ENGINE=InnoDB;\n\n-- @migrate.down\nDROP TABLE users;\n```\n\n### commands\n\n `mg [options] \u003ccommand\u003e [sections...]`\n\n#### up\n\napply current version or later.\n\n```bash\n$ mg up postgres-sample\nOK 2019060819341935 to postgres-sample is testdata/postgres/migrates/2019060819341935_users.sql\nOK 2019060819341948 to postgres-sample is testdata/postgres/seeds/2019060819341948_users.sql\n```\n\n#### down\n\nback to previous version.\n\n```bash\n$ mg down postgres-sample\nOK 2019060819341948 to postgres-sample is testdata/postgres/seeds/2019060819341948_users.sql\n```\n\n#### status\n\ndisplay the current applied status.\n\n```bash\n$ mg status postgres-sample\nVersion of postgres-sample:\n    unapplied:\n        2019060819341811 testdata/postgres/seeds/2019060819341811_jobs.sql\n    current:\n        2019060819341935\n    apply:\n        2019060819341948 testdata/postgres/seeds/2019060819341948_users.sql\n```\n\nexit with 1 if there is version that has not been applied.\n\n```\nError: Section is postgres-sample There are versions that do not apply.\nexit status 1\n```\n\n#### force-up\n\napply all versions not currently applied.\n\n```bash\n$ mg force-up postgres-sample\nOK 2019060819341811 to postgres-sample is testdata/postgres/seeds/2019060819341811_jobs.sql\nOK 2019060819341948 to postgres-sample is testdata/postgres/seeds/2019060819341948_users.sql\n```\n\n### help\n```\nUsage:\n    mg [options] \u003ccommand\u003e [sections...]\nOptions:\n    -c string\n        Set configuration file. (default \"mg.toml\")\n    -n string\n        Create empty source file.\n    -h bool\n        This help.\n    -v bool\n        Display the version of mg.\nCommands:\n    up       Apply current version or later.\n    force-up Apply all versions not currently applied.\n    down     Back to previous version.\n    status   Display the current applied status.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnissy%2Fmg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnissy%2Fmg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnissy%2Fmg/lists"}