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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pantherx.dev/casbin-rule-migration

v0.8.0

Published

Limited casbin rule migration after code changes

Readme

Casbin Route Rules Migration

npm version

This library contains shared classes, interfaces and other non-platform specific functions. Even though the library is public, we do not provide support, or assurance for this to work now, or continue to work in the future.

So: This likely won't be useful to you unless you are working with us, or with / on one of our products.


This will do a couple of things:

  1. Read latest rules from code
  2. Load last migration and related entities from the database
  3. Run a comparison
  4. Apply changes and create new migration

Here's an example

$ node dist/src/casbin-migration
=> Get latest migration
Found migration from Fri Aug 20 2021 15:24:09 GMT+0000 (Coordinated Universal Time) with ID fa3f5530-3651-4429-9f97-c501e4ce0dc1
Comparison finished. Results:
# Remain: 81
# Update: 0
# Create: 2
# Delete: 0
Applied changes to the database. Results:
# Create: 2
# Delete: 0
FINAL LIST OF MANAGED ID's [
  1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168,
  1169, 1170, 1171, 1172, 1173, 1174, 1176, 1175, 1177,
  1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186,
  1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195,
  1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204,
  1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213,
  1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222,
  1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231,
  1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240,
  1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249,
  1250, 1251, 1252, 1253, 1254, 1255
]
=> Saving new migration with 96 entries ...

With no migrations pending:

$ node dist/src/casbin-migration
=> Get latest migration
Found migration from Mon Sep 06 2021 04:01:34 GMT+0700 (Indochina Time) with ID 93ef9980-b4c2-4157-8b3c-dd5900967822
Comparison finished. Results:
# Remain: 95
# Update: 0
# Create: 0
# Delete: 0
No changes found. Nothing to do.

Setup

Install with

npm i --save @pantherx.dev/casbin-rule-migration

Create a casbin-migration.ts in src:

import { migrate } from 'packages/casbin-rule-migration/src'
import { allRouteRules, roleResourceAccessRules } from './permissions/identity-authorization-policies/rules'

migrate(allRouteRules, roleResourceAccessRules, false)

For this to work properly:

  1. Start with an empty casbin_rule and casbin_rule_migrations table.
  2. Start the server
  3. Casbin rules will be created and initial migration saved.

From now on you can run this script, whenever there are any changes.

Notes

  • We do not "update" database entries but delete the old one, and create a new one