{"id":17138432,"url":"https://github.com/kevinburke/goose","last_synced_at":"2025-04-13T09:52:59.742Z","repository":{"id":42580200,"uuid":"55907059","full_name":"kevinburke/goose","owner":"kevinburke","description":"Maintained fork of liamstask/goose that supports ALTER TYPE, CREATE INDEX CONCURRENTLY","archived":false,"fork":false,"pushed_at":"2023-11-07T18:30:01.000Z","size":5157,"stargazers_count":2,"open_issues_count":4,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T01:22:05.338Z","etag":null,"topics":["golang","goose","sql-migration"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/kevinburke/goose","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/kevinburke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-License.md","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}},"created_at":"2016-04-10T15:32:05.000Z","updated_at":"2023-11-07T18:30:05.000Z","dependencies_parsed_at":"2024-06-19T19:00:48.718Z","dependency_job_id":"8b4b56d4-be7d-4ad5-9227-184266c25734","html_url":"https://github.com/kevinburke/goose","commit_stats":{"total_commits":230,"total_committers":23,"mean_commits":10.0,"dds":0.5782608695652174,"last_synced_commit":"0decd24fc793fdd892f71d3a943554e33a84b879"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinburke","download_url":"https://codeload.github.com/kevinburke/goose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248695303,"owners_count":21146952,"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","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":["golang","goose","sql-migration"],"created_at":"2024-10-14T20:09:38.006Z","updated_at":"2025-04-13T09:52:59.720Z","avatar_url":"https://github.com/kevinburke.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goose\n\nThis is a fork of bitbucket.org/liamstask/goose that implements several new\nfeatures:\n\n- Support for db queries that cannot be run in a transaction (CREATE INDEX\n  CONCURRENTLY, ALTER TYPE)\n- Explicit versions/tags\n- Dependency vendoring\n- Updated versions of dependencies; fixes [a sqlite3 warning][warning] on the\nlatest version of Macs.\n\n[warning]: https://github.com/mattn/go-sqlite3/issues/336\n\nI removed support for the Go migration mode.\n\ngoose is a database migration tool.\n\nYou can manage your database's evolution by creating incremental SQL scripts.\n\n# Install\n\n    $ make install\n\nThis will install the `goose` binary to your `$GOPATH/bin` directory.\n\nYou can also build goose into your own applications by importing\n`github.com/kevinburke/goose/lib/goose`. Documentation is available at\n[godoc.org](http://godoc.org/github.com/kevinburke/goose/lib/goose).\n\nNOTE: the API is still new, and may undergo some changes.\n\n# Usage\n\ngoose provides several commands to help manage your database schema.\n\n## create\n\nCreate a SQL migration:\n\n    $ goose create AddSomeColumns\n    $ goose: created db/migrations/20130106093224_AddSomeColumns.sql\n\nEdit the newly created script to define the behavior of your migration.\n\n## up\n\nApply all available migrations.\n\n    $ goose up\n    $ goose: migrating db environment 'development', current version: 0, target: 3\n    $ OK    001_basics.sql\n    $ OK    002_next.sql\n    $ OK    003_and_again.sql\n\n### option: pgschema\n\nUse the `pgschema` flag with the `up` command specify a postgres schema.\n\n    $ goose -pgschema=my_schema_name up\n    $ goose: migrating db environment 'development', current version: 0, target: 3\n    $ OK    001_basics.sql\n    $ OK    002_next.sql\n    $ OK    003_and_again.sql\n\n## down\n\nRoll back a single migration from the current version.\n\n    $ goose down\n    $ goose: migrating db environment 'development', current version: 3, target: 2\n    $ OK    003_and_again.sql\n\n## redo\n\nRoll back the most recently applied migration, then run it again.\n\n    $ goose redo\n    $ goose: migrating db environment 'development', current version: 3, target: 2\n    $ OK    003_and_again.sql\n    $ goose: migrating db environment 'development', current version: 2, target: 3\n    $ OK    003_and_again.sql\n\n## status\n\nPrint the status of all migrations:\n\n    $ goose status\n    $ goose: status for environment 'development'\n    $   Applied At                  Migration\n    $   =======================================\n    $   Sun Jan  6 11:25:03 2013 -- 001_basics.sql\n    $   Sun Jan  6 11:25:03 2013 -- 002_next.sql\n    $   Pending                  -- 003_and_again.sql\n\n## dbversion\n\nPrint the current version of the database:\n\n    $ goose dbversion\n    $ goose: dbversion 002\n\n\n`goose -h` provides more detailed info on each command.\n\n\n# Migrations\n\ngoose supports migrations written in SQL - see the `goose create` command above\nfor details on how to generate them.\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, 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# Configuration\n\ngoose expects you to maintain a folder (typically called \"db\"), which contains the following:\n\n* a `dbconf.yml` file that describes the database configurations you'd like to use\n* a folder called \"migrations\" which contains `.sql` and/or `.go` scripts that implement your migrations\n\nYou may use the `-path` option to specify an alternate location for the folder containing your config and migrations.\n\nA sample `dbconf.yml` looks like\n\n```yml\ndevelopment:\n    driver: postgres\n    open: user=liam dbname=tester sslmode=disable\n```\n\nHere, `development` specifies the name of the environment, and the `driver` and `open` elements are passed directly to database/sql to access the specified database.\n\nYou may include as many environments as you like, and you can use the `-env` command line option to specify which one to use. goose defaults to using an environment called `development`.\n\ngoose will expand environment variables in the `open` element. For an example, see the Heroku section below.\n\n## Database Drivers\n\nCurrently, available dialects are: \"postgres\", \"mysql\", or \"sqlite3\".\n\nBecause migrations written in SQL are executed directly by the goose binary,\nonly drivers compiled into goose may be used for these migrations.\n\n## Queries that require a transaction\n\nSome Postgres migrations (CREATE INDEX CONCURRENTLY, ALTER TYPE) cannot be run\nin a transaction. `goose` has a special mode that can detect these queries and\nrun them outside of a transaction. To avoid partially-applied transactions,\nwe require that these can't-run-in-transaction queries consist of a single\nstatement per up/down block, e.g. you can't do `ALTER TYPE ...; ALTER TYPE\n...;`.\n\n# Contributors\n\nThank you!\n\n* Josh Bleecher Snyder (josharian)\n* Abigail Walthall (ghthor)\n* Daniel Heath (danielrheath)\n* Chris Baynes (chris_baynes)\n* Michael Gerow (gerow)\n* Vytautas Šaltenis (rtfb)\n* James Cooper (coopernurse)\n* Gyepi Sam (gyepisam)\n* Matt Sherman (clipperhouse)\n* runner_mei\n* John Luebs (jkl1337)\n* Luke Hutton (lukehutton)\n* Kevin Gorjan (kevingorjan)\n* Brendan Fosberry (Fozz)\n* Nate Guerin (gusennan)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fgoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinburke%2Fgoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fgoose/lists"}