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

eslint-plugin-sequelize-node

v0.3.1

Published

Custom linting rules for Sequelize NodeJS

Downloads

9,439

Readme

eslint-plugin-sequelize-node

Collection of custom linting rules for Sequelize NodeJS

Installation

yarn add eslint-plugin-sequelize-node

Configuration

{
  "extends": [],
  "rules": {
    "sequelize-node/no-allow-null-true": "error"
  },
  "env": {},
  "plugins": ["sequelize-node"]
}

Rules

no-allow-null-true

Adding a non nullable constraint on a column leads to PG acquiring a lock on the table while it validates the constraint. On larger tables, this can result in lock contention and other issues on the Database.

As an alternative you can write a raw SQL to safely add, validate without PG having to block writes while the constraint is being added.

The following shows how you can add the constraint on an existing column. If you are adding a new column (via addColumn) with allowNull: false, best to add the column first, then add the constraint of NOT NULL safely, like mentioned below using the four statements:

1. ALTER TABLE $table-name ADD CONSTRAINT $constraint-name CHECK ($column-name IS NOT NULL) NOT VALID;

2. ALTER TABLE $table-name validate CONSTRAINT $constraint-name; -- performs seq scan but doesn't block read/writes.

3. ALTER TABLE $table-name ALTER COLUMN workspace SET NOT NULL;

4. ALTER TABLE $table-name DROP CONSTRAINT $constraint-name;

NOTE: Depending on the size of the table, the validate instruction can take a while.

require-concurrently

Requires that an index created or dropped via raw SQL to include the 'CONCURRENTLY' keyword to avoid excessive locking.

no-remove-index

Using removeIndex does not allow setting concurrently: true as an option for removing the index. For that reason, this rule would disallow usage of this function in favor for a raw SQL query with CONCURRENTLY:

DROP INDEX CONCURRENTLY IF EXISTS my_index

always-not-valid-foreign-key

Do not use references as part of addColumn, changeColumn,addConstraint or createTable. Instead use raw SQL to add foreign key/references to a column with a NOT VALID.

NOT VALID on an ALTER statement for foreign key does not block writes against the referred table, thus making it a safer operation to run on large production tables. You can manually run VALIDATE CONSTRAINT if you desire.

For createTable its preferrable to add the column first, then using queryInterface.query add the constraint using raw SQL.

Example:

ALTER TABLE "users" ADD FOREIGN KEY ("level_id") REFERENCES "level" ("id") NOT VALID;

Working with locally

Tests


yarn test

Prettier


yarn pretty

Deployment / release

  • Bump version in package.json, create a PR and merge it to main
  • Tag and push from main
    • git checkout main && git pull
    • git tag v<$version> (same version as in package.json). Example: git tag v0.1.0
    • git push --tags origin
  • A CI build will trigger and publish the version.
    • You should see a new pipeline in CI with a publish job.