mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
ci: Fix Postgres and MySQL tests (no-changelog) (#8106)
This role query works for sqlite but [fails for Postgres and MySQL](https://github.com/n8n-io/n8n/actions/runs/7269009778/job/19805986017), so generalize by adding alias and accounting for count possibly being `string` in the resulting rows. Run in progress: https://github.com/n8n-io/n8n/actions/runs/7275986797
This commit is contained in:
parent
8df49e134d
commit
97aa38e783
6
.github/workflows/ci-postgres-mysql.yml
vendored
6
.github/workflows/ci-postgres-mysql.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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<Role> {
|
||||
|
@ -17,17 +18,17 @@ export class RoleRepository extends Repository<Role> {
|
|||
* 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<Record<string, number>>((acc, item) => {
|
||||
acc[item.role_name] = item.count;
|
||||
acc[item.role_name] = typeof item.count === 'number' ? item.count : parseInt(item.count, 10);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue