From ea168ef7a5ef5494bad15faca72c71fcf087cd67 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:52:33 +0000 Subject: [PATCH 1/6] Initial plan From b20a05981f0459972bdf6269d93816302c2e3c4e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:54:42 +0000 Subject: [PATCH 2/6] Rewrite CI workflow and README to match typeorm-adapter pattern Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- .github/workflows/ci.yml | 104 +++++++++++++++++++++++++-------------- README.md | 94 ++++++++++++++++++++--------------- 2 files changed, 122 insertions(+), 76 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23a1364b..5eb47110 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,63 +1,95 @@ -name: ci +name: CI on: [push, pull_request] jobs: - build: + lint: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 - services: - mysql: - image: mysql:latest - ports: - - 3306:3306 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + - name: Set up Node.js + uses: actions/setup-node@v2.1.5 + + - name: Install Dependency + run: yarn install + + - name: Run Lint + run: yarn run lint + + - name: Run Format Check + run: yarn run format:check + coverage: + needs: [lint] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + + - name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql database: casbin + mysql root password: password + + - name: Set up Node.js + uses: actions/setup-node@v2.1.5 with: - node-version: 12 - - run: yarn install --frozen-lockfile - - run: mysql --host 127.0.0.1 --port 3306 -uroot -p -e "CREATE DATABASE casbin" - - run: yarn format:check - - run: yarn lint - - run: yarn run jest --coverage --forceExit - - name: Coveralls Parallel + node-version: ^20 + + - name: Install Dependency + run: yarn install + + - name: Run Coverage + run: yarn run jest --coverage --forceExit + + - name: Coveralls uses: coverallsapp/github-action@master with: - github-token: ${{ secrets.github_token }} + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel: true - finish: - needs: build + test: + needs: [lint] runs-on: ubuntu-latest + strategy: + matrix: + node: [^18, ^20] steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master + - uses: actions/checkout@v2 + + - name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql database: casbin + mysql root password: password + + - name: Set up Node.js + uses: actions/setup-node@v3 with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + node-version: ${{ matrix.node }} + + - name: Install Dependency + run: yarn install + + - name: Run Unit test + run: yarn run test semantic-release: - needs: [finish, build] + needs: [lint, test, coverage] runs-on: ubuntu-latest - services: - mysql: - image: mysql:latest - ports: - - 3306:3306 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 steps: - uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: ^20 + - name: Run semantic-release if: github.repository == 'node-casbin/sequelize-adapter' && github.event_name == 'push' run: | - yarn install --frozen-lockfile - mysql --host 127.0.0.1 --port 3306 -uroot -p -e "CREATE DATABASE casbin" + yarn install yarn run prepack yarn run release env: diff --git a/README.md b/README.md index ea338d62..3613f36c 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,22 @@ -# Sequelize Adapter - +Sequelize Adapter +==== +[![CI](https://github.com/node-casbin/sequelize-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/sequelize-adapter/actions/workflows/ci.yml) +[![Coverage Status](https://coveralls.io/repos/github/node-casbin/sequelize-adapter/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/sequelize-adapter?branch=master) [![NPM version][npm-image]][npm-url] [![NPM download][download-image]][download-url] -[![codebeat badge](https://codebeat.co/badges/c17c9ee1-da42-4db3-8047-9574ad2b23b1)](https://codebeat.co/projects/github-com-node-casbin-sequelize-adapter-master) -[![ci](https://github.com/node-casbin/sequelize-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/sequelize-adapter/actions/workflows/ci.yml) -[![Coverage Status](https://coveralls.io/repos/github/node-casbin/sequelize-adapter/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/sequelize-adapter?branch=master) [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN) [npm-image]: https://img.shields.io/npm/v/casbin-sequelize-adapter.svg?style=flat-square -[npm-url]: https://npmjs.org/package/casbin-sequelize-adapter +[npm-url]: https://npmjs.com/package/casbin-sequelize-adapter [download-image]: https://img.shields.io/npm/dm/casbin-sequelize-adapter.svg?style=flat-square -[download-url]: https://npmjs.org/package/casbin-sequelize-adapter +[download-url]: https://npmjs.com/package/casbin-sequelize-adapter Sequelize Adapter is the [Sequelize](https://github.com/sequelize/sequelize) adapter for [Node-Casbin](https://github.com/casbin/node-casbin). With this library, Node-Casbin can load policy from Sequelize supported database or save policy to it. Based on [Officially Supported Databases](http://docs.sequelizejs.com/), the current supported databases are: -- PostgreSQL - MySQL +- PostgreSQL - SQLite - MSSQL @@ -25,56 +24,71 @@ You may find other 3rd-party supported DBs in Sequelize website or other places. ## Installation -NPM Install + npm install casbin-sequelize-adapter -```bash -npm install casbin-sequelize-adapter --save -``` +## Simple Example -Yarn Install +```typescript +import { newEnforcer } from 'casbin'; +import { SequelizeAdapter } from 'casbin-sequelize-adapter'; -```bash -yarn add casbin-sequelize-adapter -``` +async function myFunction() { + // Initialize a Sequelize adapter and use it in a Node-Casbin enforcer: + // The adapter can not automatically create database. + // But the adapter will automatically create and use the table named "casbin_rule". + // I think ORM should not automatically create databases. + const a = await SequelizeAdapter.newAdapter({ + username: 'root', + password: '', + database: 'casbin', + dialect: 'mysql', + }); -## Testing Locally + const e = await newEnforcer('examples/rbac_model.conf', a); -Start mysql for tests: + // Load the policy from DB. + await e.loadPolicy(); -```bash -docker compose up -d -``` + // Check the permission. + await e.enforce('alice', 'data1', 'read'); -```bash -yarn test + // Modify the policy. + // await e.addPolicy(...); + // await e.removePolicy(...); + + // Save the policy back to DB. + await e.savePolicy(); +} ``` -## Simple Example +## Simple Filter Example ```typescript -import casbin from 'casbin'; +import { newEnforcer } from 'casbin'; import { SequelizeAdapter } from 'casbin-sequelize-adapter'; async function myFunction() { // Initialize a Sequelize adapter and use it in a Node-Casbin enforcer: // The adapter can not automatically create database. - // But the adapter will automatically and use the table named "casbin_rule". - // The second boolean argument: autoCreateTable determines whether the adapter will automatically create the "casbin_rule" table. - // ORM should not create databases automatically. - const a = await SequelizeAdapter.newAdapter( - { - username: 'root', - password: '', - database: 'casbin', - dialect: 'mysql', - }, - true, - ); - - const e = await casbin.newEnforcer('examples/rbac_model.conf', a); + // But the adapter will automatically create and use the table named "casbin_rule". + // I think ORM should not automatically create databases. + const a = await SequelizeAdapter.newAdapter({ + username: 'root', + password: '', + database: 'casbin', + dialect: 'mysql', + }); + + const e = await newEnforcer('examples/rbac_model.conf', a); + + // Load the filtered policy from DB. + await e.loadFilteredPolicy({ + 'ptype': 'p', + 'v0': 'alice' + }); // Check the permission. - e.enforce('alice', 'data1', 'read'); + await e.enforce('alice', 'data1', 'read'); // Modify the policy. // await e.addPolicy(...); From b416b9647701cbe78708851ae1fa6f58b7adbad7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:57:27 +0000 Subject: [PATCH 3/6] Fix code review issues: remove MySQL passwords, fix node version syntax, remove quotes from object keys Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- .github/workflows/ci.yml | 8 +++----- README.md | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5eb47110..b1308906 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,12 +30,11 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin - mysql root password: password - name: Set up Node.js uses: actions/setup-node@v2.1.5 with: - node-version: ^20 + node-version: 20 - name: Install Dependency run: yarn install @@ -54,7 +53,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [^18, ^20] + node: ['18', '20'] steps: - uses: actions/checkout@v2 @@ -62,7 +61,6 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin - mysql root password: password - name: Set up Node.js uses: actions/setup-node@v3 @@ -84,7 +82,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: ^20 + node-version: 20 - name: Run semantic-release if: github.repository == 'node-casbin/sequelize-adapter' && github.event_name == 'push' diff --git a/README.md b/README.md index 3613f36c..6ff243c7 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ async function myFunction() { // Load the filtered policy from DB. await e.loadFilteredPolicy({ - 'ptype': 'p', - 'v0': 'alice' + ptype: 'p', + v0: 'alice' }); // Check the permission. From 1b97bedae33b3ca0dc97213e1069778cc9a02b2e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:58:38 +0000 Subject: [PATCH 4/6] Add workflow permissions to fix security issues Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1308906..5e9c74c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,8 @@ on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v2 @@ -23,6 +25,8 @@ jobs: coverage: needs: [lint] runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v2 @@ -51,6 +55,8 @@ jobs: test: needs: [lint] runs-on: ubuntu-latest + permissions: + contents: read strategy: matrix: node: ['18', '20'] @@ -76,6 +82,8 @@ jobs: semantic-release: needs: [lint, test, coverage] runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v2 From e22fc967aa2af6bd3b29369bfe4220c5bc7a80af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 14:12:03 +0000 Subject: [PATCH 5/6] Drop Node.js 18 support and add MySQL root password to fix CI Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e9c74c0..012f8431 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin + mysql root password: password - name: Set up Node.js uses: actions/setup-node@v2.1.5 @@ -57,9 +58,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - strategy: - matrix: - node: ['18', '20'] steps: - uses: actions/checkout@v2 @@ -67,11 +65,12 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin + mysql root password: password - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: ${{ matrix.node }} + node-version: 20 - name: Install Dependency run: yarn install From 999fb1f4f5f0b72ba009caa75f80ee474d551a98 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 14:19:48 +0000 Subject: [PATCH 6/6] Remove MySQL root password to match test configuration Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 012f8431..119f2e6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin - mysql root password: password - name: Set up Node.js uses: actions/setup-node@v2.1.5 @@ -65,7 +64,6 @@ jobs: uses: mirromutth/mysql-action@v1.1 with: mysql database: casbin - mysql root password: password - name: Set up Node.js uses: actions/setup-node@v3