{"id":19723521,"url":"https://github.com/remind101/migrate","last_synced_at":"2026-03-06T18:04:17.143Z","repository":{"id":57480621,"uuid":"56293777","full_name":"remind101/migrate","owner":"remind101","description":"Simple migrations for database/sql","archived":false,"fork":false,"pushed_at":"2017-07-29T03:19:35.000Z","size":13,"stargazers_count":40,"open_issues_count":1,"forks_count":2,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-04-29T22:36:32.139Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/remind101/migrate","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remind101.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":"2016-04-15T05:36:11.000Z","updated_at":"2021-09-12T10:13:31.000Z","dependencies_parsed_at":"2022-09-26T17:41:15.203Z","dependency_job_id":null,"html_url":"https://github.com/remind101/migrate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/remind101/migrate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fmigrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fmigrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fmigrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fmigrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remind101","download_url":"https://codeload.github.com/remind101/migrate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fmigrate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262166319,"owners_count":23269022,"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":[],"created_at":"2024-11-11T23:22:29.553Z","updated_at":"2026-03-06T18:04:12.002Z","avatar_url":"https://github.com/remind101.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Migrate\n\n[![Build Status](https://travis-ci.org/remind101/migrate.svg?branch=master)](https://travis-ci.org/remind101/migrate)\n\nMigrate is a Go library for doing migrations. It's stupidly simple and gets out of your way.\n\n## Features\n\n* It's only dependency is `database/sql`.\n* It supports any type of migration you want to run (e.g. raw sql, or Go code).\n* It doesn't provide a command. It's designed to be embedded in projects and used exclusively as a library.\n\n## Usage\n\n```go\nmigrations := []migrate.Migration{\n\t{\n\t\tID: 1,\n\t\tUp: func(tx *sql.Tx) error {\n\t\t\t_, err := tx.Exec(\"CREATE TABLE people (id int)\")\n\t\t\treturn err\n\t\t},\n\t\tDown: func(tx *sql.Tx) error {\n\t\t\t_, err := tx.Exec(\"DROP TABLE people\")\n\t\t\treturn err\n\t\t},\n\t},\n\t{\n\t\tID: 2,\n\t\t// For simple sql migrations, you can use the migrate.Queries\n\t\t// helper.\n\t\tUp: migrate.Queries([]string{\n\t\t\t\"ALTER TABLE people ADD COLUMN first_name text\",\n\t\t}),\n\t\tDown: func(tx *sql.Tx) error {\n\t\t\t// It's not possible to remove a column with\n\t\t\t// sqlite.\n\t\t\t_, err := tx.Exec(\"SELECT 1 FROM people\")\n\t\t\treturn err\n\t\t},\n\t},\n}\n\ndb, _ := sql.Open(\"sqlite3\", \":memory:\")\n_ = migrate.Exec(db, migrate.Up, migrations...)\n```\n\n### Locking\n\nAll migrations are run in a transaction, but if you attempt to run a single long running migration concurrently, you could run into a deadlock. For Postgres connections, `migrate` can use [pg_advisory_lock](http://www.postgresql.org/docs/9.1/static/explicit-locking.html) to ensure that only 1 migration is run at a time.\n\nTo use this, simply instantiate a `Migrator` instance using `migrate.NewPostgresMigrator`:\n\n```go\nmigrator := NewPostgresMigrator(db)\n_ = migrator.Exec(migrate.Up, migrations...)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremind101%2Fmigrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremind101%2Fmigrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremind101%2Fmigrate/lists"}