Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eiskalteschatten/sequelize-migration-wrapper

A wrapper for migrating databases using Sequelize and Umzug.
https://github.com/eiskalteschatten/sequelize-migration-wrapper

database migration mysql nodejs postgresql sequelize sql sqlite umzug

Last synced: 6 days ago
JSON representation

A wrapper for migrating databases using Sequelize and Umzug.

Awesome Lists containing this project

README

        

# sequelize-migration-wrapper

> A wrapper for migrating databases using Sequelize and Umzug.

## Table of Contents

- Requirements
- Install
- Usage
- API
- Release Notes
- Maintainer

## Requirements

This module is tested with Node.js 14. It might work with Node.js >= 12, but is not tested.

## Install

```
npm install --save sequelize-migration-wrapper
```

## Usage

### Initialization

```js
import { setupMigration } from 'sequelize-migration-wrapper'; // TypeScript
const { setupMigration } = require('sequelize-migration-wrapper'); // CommonJS

const sequelize = new Sequelize({...});

setupMigration({
sequelize,
path: 'path/to/migration/scripts',
filePattern: /\.js$/
});
```

#### Options

- sequelize (no default, must be a Sequelize instance; required),
- path (no default; required),
- filePattern (default: `/\.js$/`)

## API

### migrate()

Runs through all migration scripts in the configured folder. Umzug automatically saves which migration scripts have already been run, so it will not re-run those.

```js
await migrateDb.migrate();
```

### getStatus()

Get the current status of the migration

```js
const status = await migrateDb.getStatus();
```

### migrateNext()

Iteratively run through migration scripts.

```js
for (const i in numberOfScriptsOrSomething) {
await migrateDb.migrateNext();
}
```

### reset()

Undo the last migration using Umzug's `down` function. This will only work if your migration scripts provide a `down` function. See [Umzug's documentation](https://github.com/sequelize/umzug#migrations) for more details.

```js
await migrateDb.reset();
```

### resetPrev()

Iteratively undo a migration. This will only work if your migration scripts provide a `down` function. See [Umzug's documentation](https://github.com/sequelize/umzug#migrations) for more details.

```js
for (const i in numberOfScriptsOrSomething) {
await migrateDb.resetPrev();
}
```

## Release Notes

### 1.0.1

- Security updates

### 1.0.0

- Complete rewrite in TypeScript
- Support for Sequelize 6

### 0.1.1

- Update dependencies to fix security vulnerabilities

### 0.1.0

- Initial release

## Maintainer

This modules is maintained by Alex Seifert ([Website](https://www.alexseifert.com), [Github](https://github.com/eiskalteschatten)).