ACL Sequelize
node_acl implementation for Sequelize Currently working only with Postgres.
Installation
npm install sequelize
npm install pg
npm install acl
npm install acl-sequelize-backend
Setup
var NodeAcl = ;var Sequelize = ;var SequelizeBackend = ;var db = 'postgres://postgres:myawesomepw@127.0.0.1:5432/myawesomedb'; var aclOptions = {};var tablePrefix = 'acl_'; var acl = db tablePrefix aclOptions;
API
new SequelizeBackend(db, prefix, options)
Arguments
db Function Sequelize db instance prefix String Prefix for generated tables options Object Options provided to the backend
Options can contain these fields:
Note: These are also the defaults if nothing is provided.
var options = meta: 'meta' // Table name for meta bucket parents: 'parents' // Table name for parents bucket permissions: 'permissions' // Table name for permissions bucket resources: 'resources' // Table name for resources bucket roles: 'roles' // Table name for roles bucket users: 'users' // Table name for users bucket sync: true // Should tables be automatically created using sequelize sync method debug: false // Enable debug (shows sql on sync if enabled);
Migrations
If you want to use migrations to generate tables instead of automatic sync, You can pull them from SequelizeBackend like this:
First, make sure you disable automatic sync when initializing acl:
var acl = db 'acl_' sync: false;
Then generate migration file and add this to it:
// migrations/add_acl.js var SequelizeBackend = ; moduleexports = { var options = prefix: 'acl_' ; return SequelizeBackendmigration; } { var options = prefix: 'acl_' ; return SequelizeBackendmigration; };
Both up
and down
methods accept 3rd parameter options
which can contain table names for each bucket
var options = prefix: '' // Prefix for table names meta: 'meta' // Table name for meta bucket parents: 'parents' // Table name for parents bucket permissions: 'permissions' // Table name for permissions bucket resources: 'resources' // Table name for resources bucket roles: 'roles' // Table name for roles bucket users: 'users' // Table name for users bucket;
NOTE: Make sure that table names and prefix provided here match with table names and prefix provided to the backend.
It is recommended to just use defaults in order to avoid any issues with naming.
Tests
npm test