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

@luxuryescapes/lib-db

v1.2.0

Published

DB scripts

Downloads

3,872

Readme

lib-db

Common database scripts. These scripts require a postgres db container to be running. You can start these here infra-le-local-dev

Installation

See example PR, or follow instructions below:

yarn add -D @luxuryescapes/lib-db

Configuration

You can optionally create a file called .lib-db.config to specify configuration This file format should be key value like below

APP_NAME=my_app
TEST_HEROKU_APP_NAME=my_heroku_app_name
DB_CONTAINER=postgres13
EXCLUDE_TABLES="big_table;big_table_2;personal\*"

Usage

Easiest way is to use in your repository's npm scripts

{
  "scripts": {
    "db:pull:test": "lib-db heroku-pull-test my_app my_heroku_app_name"
  }
}

heroku-pull-test

Note: If the DB you are backing up is large, please consider using the heroku-capture-test, heroku-backup-test & heroku-restore-test commands instead.

lib-db heroku-pull-test <app_name> <heroku_app_name>

This script will pull down the database from the specified heroku app into a database called <app_name>_development

So for example if you do the following

lib-db heroku-pull-test svc_users test-svc-users

It will pull down the database from the heroku app named test-svc-users into a local db named svc_users_development

You can omit the arguments if you have APP_NAME and TEST_HEROKU_APP_NAME defined in your .lib-db.config file

You can omit table data by setting the EXCLUDE_TABLES env var in .lib-db.config this is a ; seperated list of table names. Make sure you quote this list so the ; character is escaped. If you are using a wildcard * this will need to be explicitly escaped

heroku-pull-prod

lib-db heroku-pull-prod <app_name> <heroku_app_name>

This script just prints an error at the moment

heroku-capture-test

lib-db heroku-capture-test <app_name> <heroku_app_name> This script will generate a manual backup in heroku for downloading.

heroku-backup-test

lib-db heroku-backup-test <app_name> <heroku_app_name> This script will download a backup of the database from the specified heroku app.

heroku-restore-test

lib-db heroku-restore-test <app_name> <heroku_app_name> This script will restore a backup of the database of the specified heroku app that is stored in your local container. Please run heroku-backup-test first to download the backup.

create

lib-db create <app_name>

Will create your db named <app_name>_development

You can omit the argument if you have APP_NAME defined in your .lib-db.config file

If you want to create a db for a different environment use the env var APP_ENV

e.g running APP_ENV=spec lib-db create my_app will create a db named my_app_spec

drop

lib-db drop <app_name>

Will drop your db named <app_name>_development

You can omit the argument if you have APP_NAME defined in your .lib-db.config file

If you want to drop a db for a different environment use the env var APP_ENV

e.g running APP_ENV=spec lib-db drop my_app will drop a db named my_app_spec

schema

lib-db schema <app_name>

Will export the schema of db named <app_name>_development to repo/schema.sql

You can omit the argument if you have APP_NAME defined in your .lib-db.config file

If you want to export the schema for a db for a different environment use the env var APP_ENV

e.g running APP_ENV=spec lib-db schema my_app will export the schema from the db named my_app_spec Alternatively you can define a different location using the REPO_DIRECTORY in your .lib-db.config file

snapshot

lib-db snapshot <app_name>

Will snapshot your db named <app_name>_development into <app_name>_development_snapshot

You can omit the argument if you have APP_NAME defined in your .lib-db.config file

snapshot-restore

lib-db snapshot-restore <app_name>

Will restore your snapshot in <app_name>_development_snapshot into <app_name>_development

You can omit the argument if you have APP_NAME defined in your .lib-db.config file

migrate-create

lib-db migrate-create <migration_name> <app_name>

This will create a migration sql file. By default it will put it in the migrations folder within the repo folder which is relative to where you ran the command Alternatively you can define a different location using the REPO_DIRECTORY in your .lib-db.config file

You can omit the app_name argument if you have APP_NAME defined in your .lib-db.config file

No Postgres with Docker usage

lib-db heroku-pull-test-no-docker Use this command if you are not running the Postgres DB in Docker, but still want to be able to pull from the DB in test environment for you service