github.com/matcornic/migrate@v3.3.2-0.20180717234201-feea45c20506+incompatible/README.md (about)

     1  [![Build Status](https://img.shields.io/travis/golang-migrate/migrate/master.svg)](https://travis-ci.org/golang-migrate/migrate)
     2  [![GoDoc](https://godoc.org/github.com/golang-migrate/migrate?status.svg)](https://godoc.org/github.com/golang-migrate/migrate)
     3  [![Coverage Status](https://img.shields.io/coveralls/github/golang-migrate/migrate/master.svg)](https://coveralls.io/github/golang-migrate/migrate?branch=master)
     4  [![packagecloud.io](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/golang-migrate/migrate?filter=debs)
     5  [![Docker Pulls](https://img.shields.io/docker/pulls/migrate/migrate.svg)](https://hub.docker.com/r/migrate/migrate/)
     6  ![Supported Go Versions](https://img.shields.io/badge/Go-1.9%2C%201.10-lightgrey.svg)
     7  [![GitHub Release](https://img.shields.io/github/release/golang-migrate/migrate.svg)](https://github.com/golang-migrate/migrate/releases)
     8  
     9  
    10  # migrate
    11  
    12  __Database migrations written in Go. Use as [CLI](#cli-usage) or import as [library](#use-in-your-go-project).__
    13  
    14   * Migrate reads migrations from [sources](#migration-sources)
    15     and applies them in correct order to a [database](#databases).
    16   * Drivers are "dumb", migrate glues everything together and makes sure the logic is bulletproof.
    17     (Keeps the drivers lightweight, too.)
    18   * Database drivers don't assume things or try to correct user input. When in doubt, fail.
    19  
    20  
    21  Looking for [v1](https://github.com/golang-migrate/migrate/tree/v1)?
    22  
    23  
    24  ## Databases
    25  
    26  Database drivers run migrations. [Add a new database?](database/driver.go)
    27  
    28    * [PostgreSQL](database/postgres)
    29    * [Redshift](database/redshift)
    30    * [Ql](database/ql)
    31    * [Cassandra](database/cassandra)
    32    * [SQLite](database/sqlite3) ([todo #165](https://github.com/mattes/migrate/issues/165))
    33    * [MySQL/ MariaDB](database/mysql)
    34    * [Neo4j](database/neo4j) ([todo #167](https://github.com/mattes/migrate/issues/167))
    35    * [MongoDB](database/mongodb) ([todo #169](https://github.com/mattes/migrate/issues/169))
    36    * [CrateDB](database/crate) ([todo #170](https://github.com/mattes/migrate/issues/170))
    37    * [Shell](database/shell) ([todo #171](https://github.com/mattes/migrate/issues/171))
    38    * [Google Cloud Spanner](database/spanner)
    39    * [CockroachDB](database/cockroachdb)
    40    * [ClickHouse](database/clickhouse)
    41  
    42  
    43  ## Migration Sources
    44  
    45  Source drivers read migrations from local or remote sources. [Add a new source?](source/driver.go)
    46  
    47    * [Filesystem](source/file) - read from fileystem
    48    * [Go-Bindata](source/go_bindata) - read from embedded binary data ([jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata))
    49    * [Github](source/github) - read from remote Github repositories
    50    * [AWS S3](source/aws_s3) - read from Amazon Web Services S3
    51    * [Google Cloud Storage](source/google_cloud_storage) - read from Google Cloud Platform Storage
    52  
    53  
    54  
    55  ## CLI usage
    56  
    57    * Simple wrapper around this library.
    58    * Handles ctrl+c (SIGINT) gracefully.
    59    * No config search paths, no config files, no magic ENV var injections.
    60  
    61  __[CLI Documentation](cli)__
    62  
    63  ### Basic usage:
    64  
    65  ```
    66  $ migrate -database postgres://localhost:5432/database up 2
    67  ```
    68  
    69  ### Docker usage
    70  
    71  ```
    72  $ docker run -v {{ migration dir }}:/migrations --network host migrate/migrate 
    73      -path=/migrations/ -database postgres://localhost:5432/database up 2
    74  ```
    75  
    76  ## Use in your Go project
    77  
    78   * API is stable and frozen for this release (v3.x).
    79   * Uses [dep](https://github.com/golang/dep) to manage dependencies
    80   * To help prevent database corruptions, it supports graceful stops via `GracefulStop chan bool`.
    81   * Bring your own logger.
    82   * Uses `io.Reader` streams internally for low memory overhead.
    83   * Thread-safe and no goroutine leaks.
    84  
    85  __[Go Documentation](https://godoc.org/github.com/golang-migrate/migrate)__
    86  
    87  ```go
    88  import (
    89      "github.com/golang-migrate/migrate"
    90      _ "github.com/golang-migrate/migrate/database/postgres"
    91      _ "github.com/golang-migrate/migrate/source/github"
    92  )
    93  
    94  func main() {
    95      m, err := migrate.New(
    96          "github://mattes:personal-access-token@mattes/migrate_test",
    97          "postgres://localhost:5432/database?sslmode=enable")
    98      m.Steps(2)
    99  }
   100  ```
   101  
   102  Want to use an existing database client?
   103  
   104  ```go
   105  import (
   106      "database/sql"
   107      _ "github.com/lib/pq"
   108      "github.com/golang-migrate/migrate"
   109      "github.com/golang-migrate/migrate/database/postgres"
   110      _ "github.com/golang-migrate/migrate/source/file"
   111  )
   112  
   113  func main() {
   114      db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
   115      driver, err := postgres.WithInstance(db, &postgres.Config{})
   116      m, err := migrate.NewWithDatabaseInstance(
   117          "file:///migrations",
   118          "postgres", driver)
   119      m.Steps(2)
   120  }
   121  ```
   122  
   123  ## Migration files
   124  
   125  Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-files-up-and-down-for-a-migration)
   126  
   127  ```
   128  1481574547_create_users_table.up.sql
   129  1481574547_create_users_table.down.sql
   130  ```
   131  
   132  [Best practices: How to write migrations.](MIGRATIONS.md)
   133  
   134  
   135  
   136  ## Development and Contributing
   137  
   138  Yes, please! [`Makefile`](Makefile) is your friend,
   139  read the [development guide](CONTRIBUTING.md).
   140  
   141  Also have a look at the [FAQ](FAQ.md).
   142  
   143  
   144  
   145  ---
   146  
   147  Looking for alternatives? [https://awesome-go.com/#database](https://awesome-go.com/#database).