-
Notifications
You must be signed in to change notification settings - Fork 180
/
revokeOnSchemas.ts
32 lines (26 loc) · 1.14 KB
/
revokeOnSchemas.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { MigrationOptions } from '../../types';
import { toArray } from '../../utils';
import type { OnlyGrantOnSchemasOptions } from './grantOnSchemas';
import type { RevokeOnObjectsOptions } from './shared';
import { asRolesStr } from './shared';
export type RevokeOnSchemasOptions = OnlyGrantOnSchemasOptions &
RevokeOnObjectsOptions;
export type RevokeOnSchemas = (revokeOptions: RevokeOnSchemasOptions) => string;
export function revokeOnSchemas(mOptions: MigrationOptions): RevokeOnSchemas {
const _revokeOnSchemas: RevokeOnSchemas = (options) => {
const {
privileges,
schemas,
roles,
onlyGrantOption = false,
cascade = false,
} = options;
const rolesStr = asRolesStr(roles, mOptions);
const schemasStr = toArray(schemas).map(mOptions.literal).join(', ');
const privilegesStr = toArray(privileges).map(String).join(', ');
const onlyGrantOptionStr = onlyGrantOption ? ' GRANT OPTION FOR' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
return `REVOKE${onlyGrantOptionStr} ${privilegesStr} ON SCHEMA ${schemasStr} FROM ${rolesStr}${cascadeStr};`;
};
return _revokeOnSchemas;
}