<commit_before>### Transporter

[![Circle CI](https://circleci.com/gh/wawandco/transporter.svg?style=svg&circle-token=<KEY>)](https://circleci.com/gh/wawandco/transporter)
[![docs](https://img.shields.io/badge/godoc-docs-blue.svg)](https://godoc.org/github.com/wawandco/transporter)


Transporter is a database migration tool (CLI), it helps you keep your databases in order by creating migration files, those migration files are Go files that run SQL commands on your database to keep multiple environments databases in sync on its structure.

#### Installation

To install Transporter please run `go get -u github.com/wawandco/transporter`, with that, the transporter command should be available.

#### Supported DBMS

Transporter supports the following DBMS's

- postgresql

  ```yml

  development:
    driver: postgres
    url: "user=username dbname=my_db_development sslmode=disable"

  ```

- mysql

  ```yml

  development:
    driver: mysql
    url: "transporter:password@tcp(mysql.local:3306)/ttest"

  ```



#### Commands

- transporter init

  `init` checks for `db` folder and creates this one and the `migrations` folder inside if these doesn't exist, also generates a `config.yml` file inside `db`.

- transporter create

  `generate` creates a migration inside the `db/migrations` folder.

- transporter up

  `up` runs all pending migrations inside the `db/migrations` folder.

- transporter down

  `down` runs last migration down.

#### Migrations

Migrations are simple `.go` files generated by transporter, these define a struct that implements 2 functions `Up` and `Down` which will be called according to the command you're calling from the CLI.

This is an example of a transporter Migration.

```go
package migrations
import "github.com/wawandco/transporter/transporter"

func init(){
  transporter.Register(&Migration{
    Identifier: 20151119112619,
    Up:         func (txn *sql.Tx) {
      txn.Exec("ALTER TABLE my_table ADD COLUMN new_column varchar(255);")
    },
    Down:       func (txn *sql.Tx) {
      txn.Exec("ALTER TABLE my_table DROP COLUMN new_column;")
    },
  })
}
```


#### Multiple Environment support

Transporter supports you to have multiple environments on the same application, these could be used to run tests against different databases.

By default is only ships with the `development` environment, which will run if you invoke the `up` and `down` commands without any other argument.

if you need to have multiple environments you could change your `db/config.yml` file as in this example:


```yml

development:
  driver: postgres
  url: "user=username dbname=my_db_development sslmode=disable"

staging:
  driver: postgres
  url: "user=username dbname=my_db_staging"
<commit_msg>[doc] changing doc, removing sql.Tx from sample migrations<commit_after>### Transporter

[![Circle CI](https://circleci.com/gh/wawandco/transporter.svg?style=svg&circle-token=<KEY>)](https://circleci.com/gh/wawandco/transporter)
[![docs](https://img.shields.io/badge/godoc-docs-blue.svg)](https://godoc.org/github.com/wawandco/transporter)


Transporter is a database migration tool (CLI), it helps you keep your databases in order by creating migration files, those migration files are Go files that run SQL commands on your database to keep multiple environments databases in sync on its structure.

#### Installation

To install Transporter please run `go get -u github.com/wawandco/transporter`, with that, the transporter command should be available.

#### Supported DBMS

Transporter supports the following DBMS's

- postgresql

  ```yml

  development:
    driver: postgres
    url: "user=username dbname=my_db_development sslmode=disable"

  ```

- mysql

  ```yml

  development:
    driver: mysql
    url: "transporter:password@tcp(mysql.local:3306)/ttest"

  ```



#### Commands

- transporter init

  `init` checks for `db` folder and creates this one and the `migrations` folder inside if these doesn't exist, also generates a `config.yml` file inside `db`.

- transporter create

  `generate` creates a migration inside the `db/migrations` folder.

- transporter up

  `up` runs all pending migrations inside the `db/migrations` folder.

- transporter down

  `down` runs last migration down.

#### Migrations

Migrations are simple `.go` files generated by transporter, these define a struct that implements 2 functions `Up` and `Down` which will be called according to the command you're calling from the CLI.

This is an example of a transporter Migration.

```go
package migrations
import "github.com/wawandco/transporter/transporter"

func init(){
  transporter.Register(&Migration{
    Identifier: 20151119112619,
    Up:         func (txn *transporter.Tx) {
      txn.Exec("ALTER TABLE my_table ADD COLUMN new_column varchar(255);")
    },
    Down:       func (txn *transporter.Tx) {
      txn.Exec("ALTER TABLE my_table DROP COLUMN new_column;")
    },
  })
}
```


#### Multiple Environment support

Transporter supports you to have multiple environments on the same application, these could be used to run tests against different databases.

By default is only ships with the `development` environment, which will run if you invoke the `up` and `down` commands without any other argument.

if you need to have multiple environments you could change your `db/config.yml` file as in this example:


```yml

development:
  driver: postgres
  url: "user=username dbname=my_db_development sslmode=disable"

staging:
  driver: postgres
  url: "user=username dbname=my_db_staging"

{'fraction_non_alphanumeric': 0.09604621772883191, 'fraction_numerical': 0.0079436721429861, 'mean_word_length': 4.32180595581172, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2291618', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1590, 'n_words': 597}