-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathdropExtension.ts
29 lines (22 loc) · 952 Bytes
/
dropExtension.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
import type { MigrationOptions } from '../../migrationOptions';
import { toArray } from '../../utils';
import type { DropOptions } from '../generalTypes';
import type { StringExtension } from './shared';
export type DropExtensionOptions = DropOptions;
export type DropExtension = (
extension: StringExtension | StringExtension[],
dropOptions?: DropExtensionOptions
) => string | string[];
export function dropExtension(mOptions: MigrationOptions): DropExtension {
const _drop: DropExtension = (_extensions, options = {}) => {
const { ifExists = false, cascade = false } = options;
const extensions = toArray(_extensions);
const ifExistsStr = ifExists ? ' IF EXISTS' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
return extensions.map((extension) => {
const extensionStr = mOptions.literal(extension);
return `DROP EXTENSION${ifExistsStr} ${extensionStr}${cascadeStr};`;
});
};
return _drop;
}