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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hazardco/hazardco-database

v3.25.1-ai.2

Published

Contains source code to interact with the HazardCo database

Readme

HazardCo Database 🐘

This repository contains the source code for working with the Postgres database which we use at HazardCo.

Tech

The HazardCo Database repository uses the following technology at it's core:

  • Postgres - The database we use
  • RDS - The AWS service we use for hosting our database in the cloud
  • TypeORM - The ORM we use for modelling Postgres tables and for defining controllers for database interactions
  • Docker - For running containerised unit tests
  • SQL - For documenting and versioning the state of the database at any given time
  • PGAdmin4 - GUI for working with the database

Getting started

Developing

Clone the repository to your local machine:

$ git clone [email protected]:hazardco-ltd/hazardco-database.git

Install the dependencies

$ npm i

Connecting to the Database

We don't run a insance of Postgres locally when we're working on the database. We just use the version in RDS for the relevant environment. Here are some steps on getting set up:

  1. Download the AWS Session manager plugin (you'll only have to do this once):
$ sudo curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
  1. Install the plugin:
$ sudo dpkg -i session-manager-plugin.deb
  1. Setup the connection:
$ nohup timeout 1800 aws ssm start-session --region ap-southeast-2 --target "i-0d7ce6daeb4b759ca" --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host="<HOST_NAME>",portNumber="5432",localPortNumber="5436" >> session_id.txt
  1. You can also use the following command to do setup a connection:
$ aws ssm start-session --region ap-southeast-2 --target "i-0d7ce6daeb4b759ca" --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host="<HOST_NAME>",portNumber="5432",localPortNumber="5436"

Every time you want to connect to the database, you'll just need to run either step 3 or 4 (it doesn't really matter which one).

Whichever command you use, make sure to swap out <HOST_NAME> with the remote host address for your environment. This will be one of the following: | Environment | Host | | --- | --- | | dev | db-441606397117-dev.cubavn9prmt5.ap-southeast-2.rds.amazonaws.com | | hc1 | db-441606397117-hc1.cubavn9prmt5.ap-southeast-2.rds.amazonaws.com | | uat | db-441606397117-uat.cubavn9prmt5.ap-southeast-2.rds.amazonaws.com | | production | db-441606397117-prod.cubavn9prmt5.ap-southeast-2.rds.amazonaws.com |

For more information, check out the full documentation on Confluence.

Folder Structure

All the main database code lives in the src/postgres/ directory. There are subfolders here which contain files for different purposes:

  • controllers/ - Files with TypeORM classes for performing queries on the database. These follow the naming convention [MODEL_NAME]Db.ts
  • controllers/__test__/ - Test files for controllers. These follow the naming convention [FILE_TO_TEST].spec.ts
  • entities/ - Files with TypeORM classes for modelling a database table and the relationships between multiple tables. These follow the naming convention of simply the name of the corresponding database table, but in PascalCase
  • helpers/ - General reusable helper functions for use within controllers and other files
  • versions/ - SQL files used to maintain a history of the database schema over time
src/
├─ postgres/
│  ├─ controllers/
│  │  ├─ __test__/
│  │  │  ├─ ArtefactDb.spec.ts
│  │  ├─ ArtefactDb.ts
│  │  ├─ index.ts
│  ├─ entities/
│  │  ├─ index.ts
│  │  ├─ Artefact.ts
│  ├─ helpers/
│  │  ├─ __test__/
│  │  │  ├─ Contractor.spec.ts
│  │  ├─ Contractor.ts
│  │  ├─ index.ts
│  ├─ versions/
│  │  ├─ v0.sql
│  │  ├─ v1.sql
│  │  ├─ unreleased.sql

Versioning

The version files (such as v0.sql and v1.sql) files are used to record the schema of the database at each production release. The version files can be run one after another to completely rebuild the shape of the database as needed.

Each version is considered frozen when it gets to production, so you cannot edit any of these files after they're been released. If you want to modify a table that was created in a previous version, you'll need to created another version file with a statement to ALTER the table.

When you're developing, make any SQL changes to the unreleased.sql file. This makes sure that there is only one new version file per release and conflicts can easily be sorted out in the single unreleased.sql file.

Once we're ready for a UAT release, a new v[next].sql file should be created with the number of the next version (so if the latest version file is v2.sql, the new file will be called v3.sql). The code in unreleased.sql is then moved to the new version file.

IMPORTANT: the last statement in a version file should be the following statement:

-- VERSION is the number of the version file
UPDATE configuration SET value = VERSION WHERE key = 'version';

Refer to the diagram below for the steps:

Testing

Unit testing for the repo is done with Jest and uses Docker to create a test database that we can perform queries and make assertions on. The point of unit testing in this repo is to make sure that a method on particular controller class (whether its a simple query or a complex one) returns the data we expect.

To run the tests:

$ npm test

Supporting resources for testing

  • test-helpers/factories - A directory for Factories. Factories are used for creating dummy objects to represent data we'd save in Postgres tables
  • docker-compose.yml - A YML file is used by docker to create the containers we need for testing