0.8.0 • Published 2 years ago

@pantherx.dev/casbin-rule-migration v0.8.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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
0.7.35

2 years ago

0.8.0

2 years ago

0.7.29

2 years ago

0.6.74

2 years ago

0.7.0

2 years ago

0.6.48

2 years ago

0.6.36

2 years ago

0.5.7

2 years ago

0.6.16

2 years ago

0.6.0

2 years ago

0.4.20

2 years ago

0.4.21

2 years ago

0.4.28

2 years ago

0.4.29

2 years ago

0.4.27

2 years ago

0.4.24

2 years ago

0.4.25

2 years ago

0.4.22

2 years ago

0.4.19

2 years ago

0.4.30

2 years ago

0.4.13

2 years ago

0.4.36

2 years ago

0.4.11

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.64

2 years ago

0.3.52

2 years ago

0.3.40

3 years ago

0.3.61

2 years ago

0.3.70

2 years ago

0.3.69

2 years ago

0.3.67

2 years ago

0.3.66

2 years ago

0.3.55

2 years ago

0.3.65

2 years ago

0.3.31

3 years ago

0.3.30

3 years ago

0.3.37

3 years ago

0.3.36

3 years ago

0.3.35

3 years ago

0.3.34

3 years ago

0.3.29

3 years ago

0.3.28

3 years ago

0.3.27

3 years ago

0.3.26

3 years ago