# node-mini-migrations

> A very small, lightweight and flexible migrations library unconcerned with what database you use

Latest version **6.0.1** (published 2022-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-mini-migrations
pnpm add node-mini-migrations
yarn add node-mini-migrations
bun add node-mini-migrations
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2022-11-13 |
| First published | 2019-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mark Wylde |
| Maintainers | markwylde |

## Links

- npm: https://www.npmjs.com/package/node-mini-migrations
- Repository: https://github.com/markwylde/node-mini-migrations
- Homepage: https://github.com/markwylde/node-mini-migrations#readme
- Issues: https://github.com/markwylde/node-mini-migrations/issues
- npm.io page: https://npm.io/package/node-mini-migrations

## Recent versions

- 6.0.1 (latest) — 2022-11-13
- 6.0.0 — 2022-11-13
- 5.0.0 — 2020-09-29
- 4.0.4 — 2020-04-26
- 4.0.3 — 2020-04-26
- 4.0.2 — 2020-04-26
- 4.0.1 — 2020-04-26
- 4.0.0 — 2020-04-26
- 2.1.1 — 2019-11-07
- 2.1.0 — 2019-11-07
- 2.0.1 — 2019-11-07
- 2.0.0 — 2019-11-07
- 1.3.0 — 2019-11-07
- 1.0.0 — 2019-03-09
- 0.0.2 — 2019-03-07

## README

# Mini Migrations for NodeJS
A really simple node migrations library that is completely independent of any database or file system.

## Installation
```bash
npm install --save node-mini-migrations
```

## Example Usage
### driver
```javascript
import sqlite from 'sqlite-fp/promises.js';
import up from 'node-mini-migrations/up.js';
import getMigrationsFromDirectory from 'node-mini-migrations/getMigrationsFromDirectory.js';

function migrator (db) {
  return {
    init: (direction) => {
      return sqlite.run(db, 'CREATE TABLE IF NOT EXISTS _migrations (file TEXT PRIMARY KEY);');
    },

    getMigrationState: (id) => {
      return sqlite.getOne(db, 'SELECT file FROM _migrations WHERE file = ?', [id]);
    },

    setMigrationUp: (id) => {
      return sqlite.run(db, 'INSERT INTO _migrations (file) VALUES (?)', [id]);
    },

    setMigrationDown: (id) => {
      return sqlite.run(db, 'DELETE FROM _migrations WHERE file = ?', [id]);
    },

    handler: (fn) => fn(db)
  };
};

const db = await sqlite.connect('./test.sqlite');
await up(
  migrator(db),
  getMigrationsFromDirectory('./test/migrations')
);
```

### migration
```javascript
export function up (db) {
  return db.exec('CREATE TABLE test_table (test TEXT)')
}

export function down (db) {
  return db.exec('DROP TABLE test_table')
}
```

## License
This project is licensed under the terms of the MIT license.

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