Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@pantherx.dev/casbin-rule-migration

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pantherx.dev/casbin-rule-migration

Limited casbin rule migration after code changes

latest
npmnpm
Version
0.8.0
Version published
Maintainers
1
Created
Source

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:

  • Read latest rules from code
  • Load last migration and related entities from the database
  • Run a comparison
  • 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:

  • Start with an empty casbin_rule and casbin_rule_migrations table.
  • Start the server
  • 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

FAQs

Package last updated on 03 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts