node-casbin / mongoose-adapter

Mongoose adapter for Casbin
https://github.com/casbin/node-casbin
Apache License 2.0
33 stars 32 forks source link

Create a migration feature for Casbin schema changes #63

Open Sefriol opened 2 years ago

Sefriol commented 2 years ago

Following up the discussion had here, mongoose adapter needs a way to adapt possible schema changes to ensure that previous users of the adapter have a possibility reliable and documented way to upgrade to a new version.

This requires some thinking and design. However the bare minimum should involve:

  1. Migrations are done via transactions if available.
  2. You should be able to downgrade a migration as well. Incase there are some something goes wrong.
  3. Adapter should probably check that each migration is done before being operational.
  4. Migrations should be put under tests.
casbin-bot commented 2 years ago

@Gabriel-403 @Zxilly @kingiw @nodece

Sefriol commented 2 years ago

Possible solutions to use: https://github.com/balmasi/migrate-mongoose https://github.com/seppevs/migrate-mongo

Shivansh-yadav13 commented 2 years ago

hey, @Sefriol I have some idea with migrate-mongo but how is it going to be a feature of the adapter? I am a little confused.

Sefriol commented 2 years ago

Adapter needs to identify that database schema is old and needs to be updated before use. migrate-mongo would take care of the update and then adapter would work as expected.

I think in this particular case it would just update (up()) all documents with p_type to ptype and possibility to downgrade (down()), converting all documents back to p_type. This should be quite reliable with MongoDB transactions.