npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simplemigration

v0.0.3

Published

yet another tool for managing databases

Downloads

5

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