diff --git a/.github/workflows/ci-postgres-mysql.yml b/.github/workflows/ci-postgres-mysql.yml index c0e4b6f742..f42afc4937 100644 --- a/.github/workflows/ci-postgres-mysql.yml +++ b/.github/workflows/ci-postgres-mysql.yml @@ -6,7 +6,7 @@ on: workflow_dispatch: pull_request: paths: - - packages/cli/src/databases/migrations/** + - packages/cli/src/databases/** concurrency: group: db-${{ github.event.pull_request.number || github.ref }} @@ -65,7 +65,7 @@ jobs: - name: Test MySQL working-directory: packages/cli - run: DB_TABLE_PREFIX=test_ pnpm test:mysql --runInBand + run: pnpm test:mysql postgres: name: Postgres @@ -98,7 +98,7 @@ jobs: - name: Test Postgres working-directory: packages/cli - run: DB_POSTGRESDB_SCHEMA=alt_schema DB_TABLE_PREFIX=test_ pnpm test:postgres --runInBand + run: pnpm test:postgres notify-on-failure: name: Notify Slack on failure diff --git a/packages/cli/package.json b/packages/cli/package.json index 62785cd5c2..880558bbbd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -37,8 +37,8 @@ "swagger": "swagger-cli", "test": "pnpm test:sqlite", "test:sqlite": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest", - "test:postgres": "N8N_LOG_LEVEL=silent DB_TYPE=postgresdb jest --no-coverage", - "test:mysql": "N8N_LOG_LEVEL=silent DB_TYPE=mysqldb jest --no-coverage", + "test:postgres": "N8N_LOG_LEVEL=silent DB_TYPE=postgresdb DB_POSTGRESDB_SCHEMA=alt_schema DB_TABLE_PREFIX=test_ jest --no-coverage", + "test:mysql": "N8N_LOG_LEVEL=silent DB_TYPE=mysqldb DB_TABLE_PREFIX=test_ jest --no-coverage", "watch": "concurrently \"tsc -w -p tsconfig.build.json\" \"tsc-alias -w -p tsconfig.build.json\"", "typeorm": "ts-node -T ../../node_modules/typeorm/cli.js" }, diff --git a/packages/cli/src/databases/repositories/role.repository.ts b/packages/cli/src/databases/repositories/role.repository.ts index 8ecee595c1..cda3726aa3 100644 --- a/packages/cli/src/databases/repositories/role.repository.ts +++ b/packages/cli/src/databases/repositories/role.repository.ts @@ -2,6 +2,7 @@ import { Service } from 'typedi'; import { DataSource, Repository } from 'typeorm'; import type { RoleNames, RoleScopes } from '../entities/Role'; import { Role } from '../entities/Role'; +import { User } from '../entities/User'; @Service() export class RoleRepository extends Repository { @@ -17,17 +18,17 @@ export class RoleRepository extends Repository { * Counts the number of users in each role, e.g. `{ admin: 2, member: 6, owner: 1 }` */ async countUsersByRole() { - type Row = { role_name: string; count: number }; + type Row = { role_name: string; count: number | string }; const rows: Row[] = await this.createQueryBuilder('role') .select('role.name') .addSelect('COUNT(user.id)', 'count') - .innerJoin('user', 'user', 'role.id = user.globalRoleId') + .innerJoin(User, 'user', 'role.id = user.globalRoleId') .groupBy('role.name') .getRawMany(); return rows.reduce>((acc, item) => { - acc[item.role_name] = item.count; + acc[item.role_name] = typeof item.count === 'number' ? item.count : parseInt(item.count, 10); return acc; }, {}); }