# simplemigration

> yet another tool for managing databases

Latest version **0.0.3** (published 2014-04-30) · 0 weekly downloads

## Install

```sh
npm install simplemigration
pnpm add simplemigration
yarn add simplemigration
bun add simplemigration
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2014-04-30 |
| First published | 2014-03-19 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.24 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Manuel Schneider |
| Maintainers | efreet |

## Links

- npm: https://www.npmjs.com/package/simplemigration
- Repository: https://github.com/manuelschneider/simplemigration
- Issues: https://github.com/manuelschneider/simplemigration/issues
- npm.io page: https://npm.io/package/simplemigration

## Dependencies (3)

- [wrench](https://npm.io/package/wrench.md) ~1.5.7
- [mongodb](https://npm.io/package/mongodb.md) ^1.3.23
- [source-map-support](https://npm.io/package/source-map-support.md) ~0.2.5

## Recent versions

- 0.0.3 (latest) — 2014-04-30
- 0.0.2 — 2014-03-20
- 0.0.0 — 2014-03-19

## README

SimpleMigration
=============

*yet another tool for managing databases*

* Store the number of applied migrations within the database, so it is with the database whatever happens to it..
* Migrations are hard to create, so each should be simple, as in just some SQL or Javascript doing somethin with a db, don't care for credentials, connects etc
* errors should be thrown in case something didn't work, preventing any further processing
* on failures, simply wipe the db and apply the dump from before the try -> no downscripts, as they are additional effort for writing and testing. If some admin wants to downgrade, (s)he'll have to patch the db manually, downgrading is generally no good idea.
* Manage the complete db lifecycle: Ensure it is accessable, create it, connect to it and purge it.
* Support for different storage types, from a fs-directory to mongo.
* Use only migration-counts as 'version', order is determined by sorting the filenames.
* Easy backup/restore methodology (eg for testing-fixtures)

## Example

### Migration

    var guests = [
        {
            "id": "123",
            "name": "Herbert Eumels",
            "customGreeting": "Hiho Eumele!",
            "acceptedInvitation": false
        }
    ];

    module.exports = function ( cb, db ) {

        db.createCollection("guests", (function (cb, err, col) {

            if (typeof(err) !== "undefined" && err !== null) {
                cb(err);
                return;
            }

            col.insert(guests, {w:1}, (function (cb, err, res) {
                if (typeof(err) !== "undefined" && err !== null) {
                    cb(err);
                    return;
                }

                if (res) {
                    db.ensureIndex("guests", "id", { w: 1}, (function (cb, err, res) {
                        if (typeof(err) !== "undefined" && err !== null) {
                            cb(err);
                            return;
                        }
                        if (res) {
                            cb();
                        } else {
                            cb(new Error("something went wrong"));
                        }
                    }).bind(this, cb));
                } else {
                    cb(new Error("something went wrong"));
                }

            }).bind(this, cb));

        }).bind(this, cb));

    };

### Usage (API)

    $ npm install simplemigration --save

    var SimpleMigration = require("simplemigration");
    db = new SimpleMigration({
        type: 'mongodb'
        host: 'localhost'
        port: 27017
        schema: "guestmanager"
        user: null
        pw: null
    }, {
        user: null
        pw: null
    })
    // the second param is for the administrative user and not required
    // for mongodb-instances without --auth.
    // When you use --auth, a 'superuser' is required as admin:
    //      use admin
    //      db.addUser({ user: "admin", pwd: "topsecret", roles: [
    //          "readWrite", "dbAdmin", "userAdmin", "readWriteAnyDatabase",
    //          "userAdminAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin"
    //      ] })

    db.isAccessable((result) ->
        // bool, test if the app can connect to the db
    )

    db.createIfNotExists((err) ->
        // create an empty database (and user) with the given config 
    )

    db.isUptodate((result) ->
        // test if the database has all migrations applied
    ,"path/to/dbMigrations")

    db.apply((err) ->
        // apply all migrations from the given dir that have not been applied yet
    , "path/to/dbMigrations")

    db.ensureReadiness((err) ->
        // make sure the db (and the user) exists, is accessable and all migrations have been applied
    , "path/to/dbMigrations")

    db.backup((dumpfile) ->
        // backup the complete database, if no file is given, the contents are returned
    , "some/dir/contents.bak")

    db.restore((err) ->
        // give it either the result from db.backup or some file
    , "some/dir/contents.bak")

    db.purge((err) ->
        // purge the database, the user, and all data
    )


## Currently supported storage types

* MongoDB

### TODO

* Filesystem dir
* Postgres
* Sqlite
* Maria
* .. ?

## License

MPL-2.0

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