-
Notifications
You must be signed in to change notification settings - Fork 181
/
revokeOnTables.ts
36 lines (30 loc) · 1.14 KB
/
revokeOnTables.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
33
34
35
36
import type { MigrationOptions } from '../../types';
import { toArray } from '../../utils';
import type {
AllTablesOptions,
CommonOnTablesOptions,
RevokeOnObjectsOptions,
SomeTablesOptions,
} from './shared';
import { asRolesStr, asTablesStr } from './shared';
export type RevokeOnTablesOptions = CommonOnTablesOptions &
(AllTablesOptions | SomeTablesOptions) &
RevokeOnObjectsOptions;
export type RevokeOnTables = (revokeOptions: RevokeOnTablesOptions) => string;
export function revokeOnTables(mOptions: MigrationOptions): RevokeOnTables {
const _revokeOnTables: RevokeOnTables = (options) => {
const {
privileges,
roles,
onlyGrantOption = false,
cascade = false,
} = options;
const rolesStr = asRolesStr(roles, mOptions);
const privilegesStr = toArray(privileges).map(String).join(', ');
const tablesStr = asTablesStr(options, mOptions);
const onlyGrantOptionStr = onlyGrantOption ? ' GRANT OPTION FOR' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
return `REVOKE${onlyGrantOptionStr} ${privilegesStr} ON ${tablesStr} FROM ${rolesStr}${cascadeStr};`;
};
return _revokeOnTables;
}