-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(triggers): reorganize operations triggers (#1083)
- Loading branch information
1 parent
ce945b5
commit 48bb57d
Showing
8 changed files
with
107 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { MigrationOptions } from '../../types'; | ||
import type { DropOptions, Name } from '../generalTypes'; | ||
|
||
export type DropTrigger = ( | ||
tableName: Name, | ||
triggerName: string, | ||
dropOptions?: DropOptions | ||
) => string | string[]; | ||
|
||
export function dropTrigger(mOptions: MigrationOptions): DropTrigger { | ||
const _drop: DropTrigger = (tableName, triggerName, options = {}) => { | ||
const { ifExists, cascade } = options; | ||
|
||
const ifExistsStr = ifExists ? ' IF EXISTS' : ''; | ||
const cascadeStr = cascade ? ' CASCADE' : ''; | ||
const triggerNameStr = mOptions.literal(triggerName); | ||
const tableNameStr = mOptions.literal(tableName); | ||
|
||
return `DROP TRIGGER${ifExistsStr} ${triggerNameStr} ON ${tableNameStr}${cascadeStr};`; | ||
}; | ||
|
||
return _drop; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './createTrigger'; | ||
export * from './dropTrigger'; | ||
export * from './renameTrigger'; | ||
export * from './shared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { MigrationOptions } from '../../types'; | ||
import type { Name } from '../generalTypes'; | ||
|
||
export type RenameTriggerFn = ( | ||
tableName: Name, | ||
oldTriggerName: string, | ||
newTriggerName: string | ||
) => string | string[]; | ||
|
||
export type RenameTrigger = RenameTriggerFn & { reverse: RenameTriggerFn }; | ||
|
||
export function renameTrigger(mOptions: MigrationOptions): RenameTrigger { | ||
const _rename: RenameTrigger = ( | ||
tableName, | ||
oldTriggerName, | ||
newTriggerName | ||
) => { | ||
const oldTriggerNameStr = mOptions.literal(oldTriggerName); | ||
const tableNameStr = mOptions.literal(tableName); | ||
const newTriggerNameStr = mOptions.literal(newTriggerName); | ||
|
||
return `ALTER TRIGGER ${oldTriggerNameStr} ON ${tableNameStr} RENAME TO ${newTriggerNameStr};`; | ||
}; | ||
|
||
_rename.reverse = (tableName, oldTriggerName, newTriggerName) => | ||
_rename(tableName, newTriggerName, oldTriggerName); | ||
|
||
return _rename; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Name, Value } from '../generalTypes'; | ||
|
||
export interface TriggerOptions { | ||
when?: 'BEFORE' | 'AFTER' | 'INSTEAD OF'; | ||
|
||
operation: string | string[]; | ||
|
||
constraint?: boolean; | ||
|
||
function?: Name; | ||
|
||
functionParams?: Value[]; | ||
|
||
level?: 'STATEMENT' | 'ROW'; | ||
|
||
condition?: string; | ||
|
||
deferrable?: boolean; | ||
|
||
deferred?: boolean; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters