# @edirect/migration

> ## Usage

Latest version **1.0.1** (published 2019-11-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @edirect/migration
pnpm add @edirect/migration
yarn add @edirect/migration
bun add @edirect/migration
```

Provides the commands `migrate`, `generate`, `rollback`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-11-25 |
| First published | 2019-11-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.9.0 |
| Dependencies | 9 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 (+6 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Btime Team |
| Maintainers | edirectamorim |

## Links

- npm: https://www.npmjs.com/package/@edirect/migration
- Repository: https://github.com/Btime/btime-migration
- Homepage: https://github.com/Btime/btime-migration#readme
- Issues: https://github.com/Btime/btime-migration/issues
- npm.io page: https://npm.io/package/@edirect/migration

## Dependencies (9)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [pg](https://npm.io/package/pg.md) ^7.4.3
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [yargs](https://npm.io/package/yargs.md) ^12.0.2
- [dotenv](https://npm.io/package/dotenv.md) ^6.0.0
- [moment](https://npm.io/package/moment.md) ^2.22.2
- [mongodb](https://npm.io/package/mongodb.md) ^3.1.6
- [pg-hstore](https://npm.io/package/pg-hstore.md) ^2.3.2
- [sequelize](https://npm.io/package/sequelize.md) ^4.38.1

## Recent versions

- 1.0.1 (latest) — 2019-11-25
- 1.0.0 — 2019-11-25

## README

# BTime V2 Migration

## :books: Table of Contents

1. [Installation](#installation)
1. [Usage](#usage)
1. [Testing](#testing)
1. [Linting](#linting)

## **Installation**
### NPM Repository
	$ npm i -S @btime/migration

### GitHub Repository
	$ npm i -S github:Btime/btime-migration

### Copy the enviroment file to your project root and configure it
	$ cp ./{PACKAGE_ROOT}/.env.dist {PROJECT_ROOT}/.env

:bulb: **TIP** Both **_migrate_** and **_rollback_** allows for the specification of a **custom env file**,
through the **`--env`** flag.

## **Usage**
To facilitate the use of this CLI tool, you might install it globally or map
its commands to the _package.json scripts_, as follows:

```json
"scripts": {
    "generate": "./node_modules/.bin/generate",
    "migrate": "./node_modules/.bin/migrate",
    "rollback": "./node_modules/.bin/rollback"
}
```
:information_source: **IMPORTANT** Don't forget that the mapping above requires
you to invoke such scripts as **npm run \<script>**. [More on NPM scripts](https://docs.npmjs.com/cli/run-script).

### **Generating a migration**

	$ generate -t sql

> **Example output:** _Generated new migration file: /home/user/projects/btime-migration/migrations/Version**20181002114415382**.js_

All run migrations get **versioned**, based on it's name - which reflects a unique timestamp. That's the version used when [**rolling back the migration**](#rolling-back-migrations).

By default, migration files are created at **`./migrations`** (project root). You can specify a custom directory by utilizing the **`--workdir`** flag:

	$ generate -t sql --workdir ./custom-mirations-dir
> The *generate*, *migrate* and *rollback* commands support a custom directory to be specified.

:information_source: **IMPORTANT**	The directory must exist in order to be used.

### **Running migrations**

	$ migrate

The above command **will run (_up_)** all migration files, considering default options (flags).

### Hitting multiple databases
The migration process might target multiple databases through the *`"--multiple"`* flag.

	$ migrate --multiple

:information_source: **IMPORTANT** Environment variables prefixed with _"MULTIPLE\__" are used in order to find target databases.

### **Rolling back migrations**

	$ rollback --version [version]

The above command **will run (down)** the specified migration, considering default options (flags).

Just like the _migrate_ command, you can make use of the **`--multiple`** flag and target multiple databases:

	$ rollback --version [version] --multiple

_All commands come with a **`--help`** flag, which displays useful information about it's usage options._

### Pushing versions - SemVer

All pushes must come with a new tag. The tag usage must consider semantic versions.

`[major version: incompatible changes].[minor version: compatible with major].[patch version: bug fixes]`

Before pushing each version, type:

- For patch changes: `npm version patch`
- For minor changes: `npm version minor`
- For major changes: `npm version major`

**The version set must also be set in `package.json` file, at `version` field.**

## Testing

Tests are run using [Mocha](https://mochajs.org) and [Chai](https://www.chaijs.com). Coverage is provided by [Istanbul CLI](https://github.com/istanbuljs/nyc).

Run test suite (coverage included)

	$ npm test

## Linting
To scan the code base and "auto-fix" all that violates the defined lint rules, run:

	$ npm run fixStyle

---
_Source: https://npm.io/package/@edirect/migration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
