github.com/vedicsoft/migrate@v3.0.2-0.20170709175710-23a2745a3ade+incompatible/README.md (about)

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