{"id":36816258,"url":"https://github.com/webnice/migrate","last_synced_at":"2026-01-12T13:53:54.797Z","repository":{"id":43189898,"uuid":"124140903","full_name":"webnice/migrate","owner":"webnice","description":"Goose database migration tool - based on https://bitbucket.org/liamstask/goose","archived":false,"fork":false,"pushed_at":"2022-07-07T13:42:40.000Z","size":5510,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"v1","last_synced_at":"2024-09-22T09:21:40.732Z","etag":null,"topics":["clickhouse","cockroach","database","golang","lib","migration","mysql","postgres","redshift","schema","sql","sqlite3","tidb","tool"],"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/webnice.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":"2018-03-06T21:28:43.000Z","updated_at":"2022-07-06T14:03:31.000Z","dependencies_parsed_at":"2022-09-26T17:51:07.626Z","dependency_job_id":null,"html_url":"https://github.com/webnice/migrate","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/webnice/migrate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webnice%2Fmigrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webnice%2Fmigrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webnice%2Fmigrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webnice%2Fmigrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webnice","download_url":"https://codeload.github.com/webnice/migrate/tar.gz/refs/heads/v1","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webnice%2Fmigrate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28339808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["clickhouse","cockroach","database","golang","lib","migration","mysql","postgres","redshift","schema","sql","sqlite3","tidb","tool"],"created_at":"2026-01-12T13:53:54.695Z","updated_at":"2026-01-12T13:53:54.769Z","avatar_url":"https://github.com/webnice.png","language":"Go","readme":"# migrate\n\n[![GoDoc](https://godoc.org/github.com/webnice/migrate/goose?status.svg)](https://godoc.org/github.com/webnice/migrate/goose)\n[![Go Report Card](https://goreportcard.com/badge/github.com/webnice/migrate)](https://goreportcard.com/report/github.com/webnice/migrate)\n[![CircleCI](https://circleci.com/gh/webnice/migrate/tree/v1.svg?style=svg)](https://circleci.com/gh/webnice/migrate/tree/v1)\n\n[comment]: \u003c\u003e ([![Coverage Status]\u0026#40;https://coveralls.io/repos/github/webnice/migrate/badge.svg?branch=v1\u0026#41;]\u0026#40;https://coveralls.io/github/webnice/migrate?branch=v1\u0026#41;)\n[comment]: \u003c\u003e ([![Build Status]\u0026#40;https://travis-ci.org/webnice/migrate.svg?branch=v1\u0026#41;]\u0026#40;https://travis-ci.org/webnice/migrate\u0026#41;)\n\nIs a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions.\n\nBased on goose lib of `bitbucket.org/liamstask/goose`\n\n# Supported databases\n\n* mysql\n* postgres\n* cockroach\n* sqlite3\n* redshift\n* clickhouse\n* tidb\n\n\n# Install\n\n\t$ go get -u github.com/webnice/migrate/gsmigrate\n\nThis will install the `gsmigrate` binary to your `$GOPATH/bin` directory.\n\n# Usage\n\n```\nusage: gsmigrate [\u003cflags\u003e] \u003ccommand\u003e [\u003cargs\u003e ...]\n\nUtility for applying database migrations\n\nFlags:\n  --help         Show context-sensitive help (also try --help-long and --help-man).\n  --dir=\".\"      Directory with migration files. Default is '.'.\n                 Overrides the default value for a flag from an environment variable by name 'GOOSE_DIR'\n  --drv=\"mysql\"  Driver of database. Support is [mysql, postgres, sqlite3, redshift, clickhouse, tidb].\n                 Overrides the default value for a flag from an environment variable by name 'GOOSE_DRV'\n  --dsn=\"root@unix(/var/run/mysql/mysql.sock)/test?parseTime=true\"\n                 Database source name (DSN).\n                 Overrides the default value for a flag from an environment variable by name 'GOOSE_DSN'\n\nCommands:\n  help [\u003ccommand\u003e...]\n    Show help.\n\n  up\n    Migrate the DB to the most recent version available\n\n  up-to [\u003cVERSION\u003e]\n    Migrate the DB to a specific VERSION\n\n  down\n    Roll back the version by 1\n\n  down-to [\u003cVERSION\u003e]\n    Roll back to a specific VERSION\n\n  redo\n    Re-run the latest migration\n\n  status\n    Dump the migration status for the current DB\n\n  version\n    Print the current version of the database\n\n  create [\u003cNAME\u003e] [\u003cTYPE\u003e]\n    Creates new migration file with next version\n```\n## Examples:\n\n```\n    gsmigrate --drv=\"sqlite3\" --dsn=\"./foo.db\" status\n    gsmigrate --drv=\"sqlite3\" --dsn=\"./foo.db\" create init sql\n    gsmigrate --drv=\"sqlite3\" --dsn=\"./foo.db\" create add_some_column sql\n    gsmigrate --drv=\"sqlite3\" --dsn=\"./foo.db\" create fetch_user_data go\n    gsmigrate --drv=\"sqlite3\" --dsn=\"./foo.db\" up\n\n    gsmigrate --drv=\"postgres\" --dsn=\"user=postgres dbname=postgres sslmode=disable\" status\n    gsmigrate --drv=\"mysql\" --dsn=\"user:password@/dbname?parseTime=true\" status\n    gsmigrate --drv=\"redshift\" --dsn=\"postgres://user:password@qwerty.us-east-1.redshift.amazonaws.com:5439/db\" status\n\t\tgsmigrate --drv=\"clickhouse\" --dsn=\"tcp://localhost:9000?username=default\u0026database=test\" status\n    gsmigrate --drv=\"tidb\" --dsn=\"user:password@/dbname?parseTime=true\" status\n```\n## create\n\nCreate a new SQL migration\n\n    $ gsmigrate create add_some_column sql\n    $ Created new file: YYYYMMDDhhmmss_add_some_column.sql\n\nEdit the newly created file to define the behavior of your migration.\n\nYou can also create a Go migration, if you then invoke it with your own goose binary:\n\n    $ gsmigrate create fetch_user_data go\n    $ Created new file: YYYYMMDDhhmmss_fetch_user_data.go\n\n## up\n\nApply all available migrations\n\n    $ gsmigrate up\n    $ OK    20180305100000_begin.sql\n    $ OK    20180306100000_next.sql\n    $ OK    20180307100000_and_again.sql\n    $ goose: no migrations to run. current version: 20180307100000\n\n## up-to\n\nMigrate up to a specific version\n\n    $ gsmigrate up-to 20180306100000\n    $ OK    20180305100000_begin.sql\n    $ OK    20180306100000_next.sql\n    $ goose: no migrations to run. current version: 20180306100000\n\n## down\n\nRoll back a single migration from the current version\n\n    $ gsmigrate down\n    $ OK    20180307100000_and_again.sql\n    $ goose: no migrations to run. current version: 20180306100000\n\n## down-to\n\nRoll back migrations to a specific version\n\n    $ gsmigrate down-to 20180305100000\n    $ OK    20180307100000_and_again.sql\n    $ OK    20180306100000_next.sql\n    $ goose: no migrations to run. current version: 20180305100000\n\n## redo\n\nRoll back the most recently applied migration, then run it again\n\n    $ gsmigrate redo\n    $ -- SQL in this section is executed when the migration is rolled back..\n    $ OK    20180307100000_and_again.sql\n    $ -- SQL in this section is executed when the migration is applied..\n    $ OK    20180307100000_and_again.sql\n\n## status\n\nPrint the status of all migrations:\n\n    $ gsmigrate status\n    $ Applied At                  Migration\n    $ =======================================\n    $ Wed Mar  7 14:57:35 2018 -- 20180305100000_begin.sql\n    $ Wed Mar  7 15:01:20 2018 -- 20180306100000_next.sql\n    $ Pending                  -- 20180307100000_and_again.sql\n\n## version\n\nPrint the current version of the database:\n\n    $ gsmigrate version\n    $ goose: version 20180306100000\n\n# Migrations\n\ngsmigrate supports migrations written in SQL or in Go.\n\n## SQL Migrations\n\nA sample SQL migration looks like:\n\n```sql\n-- +goose Up\nCREATE TABLE post (\n    id int NOT NULL,\n    title text,\n    body text,\n    PRIMARY KEY(id)\n);\n\n-- +goose Down\nDROP TABLE post;\n```\n\nNotice the annotations in the comments. Any statements following `-- +goose Up` will be executed as part of a forward migration, and any statements following `-- +goose Down` will be executed as part of a rollback.\n\nBy default, all migrations are run within a transaction. Some statements like `CREATE DATABASE`, however, cannot be run within a transaction. You may optionally add `-- +goose NO TRANSACTION` to the top of your migration\nfile in order to skip transactions within that specific migration file. Both Up and Down migrations within this file will be run without transactions.\n\nBy default, SQL statements are delimited by semicolons - in fact, query statements must end with a semicolon to be properly recognized by goose.\n\nMore complex statements (PL/pgSQL) that have semicolons within them must be annotated with `-- +goose StatementBegin` and `-- +goose StatementEnd` to be properly recognized. For example:\n\n```sql\n-- +goose Up\n-- +goose StatementBegin\nCREATE OR REPLACE FUNCTION histories_partition_creation( DATE, DATE )\nreturns void AS $$\nDECLARE\n  create_query text;\nBEGIN\n  FOR create_query IN SELECT\n      'CREATE TABLE IF NOT EXISTS histories_'\n      || TO_CHAR( d, 'YYYY_MM' )\n      || ' ( CHECK( created_at \u003e= timestamp '''\n      || TO_CHAR( d, 'YYYY-MM-DD 00:00:00' )\n      || ''' AND created_at \u003c timestamp '''\n      || TO_CHAR( d + INTERVAL '1 month', 'YYYY-MM-DD 00:00:00' )\n      || ''' ) ) inherits ( histories );'\n    FROM generate_series( $1, $2, '1 month' ) AS d\n  LOOP\n    EXECUTE create_query;\n  END LOOP;  -- LOOP END\nEND;         -- FUNCTION END\n$$\nlanguage plpgsql;\n-- +goose StatementEnd\n```\n\n## Go Migrations\n\n1. Create your own goose binary\n2. Import `github.com/webnice/migrate/goose`\n3. Register your migration functions\n4. Run goose command, ie. `goose.Up(db *sql.DB, dir string)`\n\nA sample Go migration looks like:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\n\t\"github.com/webnice/migrate/goose\"\n)\n\nfunc init() {\n\tgoose.AddMigration(Up20180307100000, Down20180307100000)\n}\n\n// Up20180307100000 Migration applied\nfunc Up20180307100000(tx *sql.Tx) (err error) {\n\t// This code is executed when the migration is applied.\n\treturn\n}\n\n// Down20180307100000 Migration rolled back\nfunc Down20180307100000(tx *sql.Tx) (err error) {\n\t// This code is executed when the migration is rolled back.\n\treturn\n}\n```\n\n## License\n\nLicensed under [MIT License](./LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebnice%2Fmigrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebnice%2Fmigrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebnice%2Fmigrate/lists"}