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

@0ti.me/postgres-db-versioning

v0.1.3

Published

A library for managing PostgresDB migrations and initialization

Downloads

7

Readme

PostgresDB Versioning

Relational databases must be versioned if their data and tables are to be migrated properly over time. This project seeks to produce an NPM module which does the heavy lifting using configuration and version data supplied by whatever depends on this module.

Configuration

{
  "connectionConfig": {
    "user": "postgres",
    "password": "postgres",
    "host": "localhost",
    "database": "postgres",
    "port": 54231
  },
  "dryRun": false
  "eventHandler": (...eventArgs) => console.error(event),
  "migrations": [
    {"version": 1, "description": "create the table a_table", "sql": "CREATE TABLE a_table (id INT);"},
    {"version": 2, "description": "add the table another_table", "sql": "CREATE TABLE another_table (id INT);"}
  ],
  "pool": {
    query: sqlString => console.error(sqlString)
  },
  "requestedVersion": 2,
  "scratch": [
    "CREATE TABLE table_name"
  ],
  "tableNameForVersions": "DatabaseVersion",
  "version": 1
}

Connection Config

If this module should manage the connection, then pass in a config object with this API: https://node-postgres.com/api/client/.

Dry Run

With this feature enabled, the steps which would be performed will be sent as events to the event handler.

Event Handler

If this is set, it will emit events (either a string for the query or an array crafted from the (...args) which will be applied to the query function call.

For example, if the eventHandler is called with multiple arguments, such as: 'SELECT * FROM x WHERE x.y = ?;' and ['fred'], then when the plan executes, it would execute something like this:

pool.query('SELECT * FROM x WHERE x.y = ?;', ['fred']);

If the eventHandler is called with just a string, like 'SELECT * FROM x;', it would execute something like this:

pool.query('SELECT * FROM x');

Migrations

Migrations should be an array of objects containing a version number, an optional description of the changes, and the sql that should be executed.

Pool

If included, this will be used blindly to send queries to the DB. It will be assumed that it implements this API: https://node-postgres.com/api/pool/. This option takes priority over "connectionConfig", so don't provide "pool" if you want to use "connectionConfig".

Requested Version

If provided, it will stop trying to migrate at the requested version. This will disable use of scratch if the "version" is greater than the "options"."requestedVersion".

If not provided, the max of "options"."version" and of the highest "version" in "options"."migrations" will be used.

Scratch

If provided, the scratch array will be used to populate the database if the "tableNameForVersions" table is not yet present. Migrations with a "version" greater than "options"."version" will be also executed by making the assumption that the "options"."version" version has been achieved.

If not provided, the migrations array will be used.

Table Name for Versions

This allows you change the name used to track versions of the DB.

Version

This should be the same as the version which is created by "scratch".