-
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(schemas): reorganize operations schemas (#1080)
- Loading branch information
1 parent
550b31f
commit 58b6010
Showing
8 changed files
with
80 additions
and
76 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { MigrationOptions } from '../../types'; | ||
import type { DropOptions, IfNotExistsOption } from '../generalTypes'; | ||
import { dropSchema } from './dropSchema'; | ||
|
||
export interface CreateSchemaOptions extends IfNotExistsOption { | ||
authorization?: string; | ||
} | ||
|
||
export type CreateSchemaFn = ( | ||
schemaName: string, | ||
schemaOptions?: CreateSchemaOptions & DropOptions | ||
) => string | string[]; | ||
|
||
export type CreateSchema = CreateSchemaFn & { reverse: CreateSchemaFn }; | ||
|
||
export function createSchema(mOptions: MigrationOptions): CreateSchema { | ||
const _create: CreateSchema = (schemaName: string, options = {}) => { | ||
const { ifNotExists, authorization } = options; | ||
|
||
const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : ''; | ||
const schemaNameStr = mOptions.literal(schemaName); | ||
const authorizationStr = authorization | ||
? ` AUTHORIZATION ${authorization}` | ||
: ''; | ||
|
||
return `CREATE SCHEMA${ifNotExistsStr} ${schemaNameStr}${authorizationStr};`; | ||
}; | ||
|
||
_create.reverse = dropSchema(mOptions); | ||
|
||
return _create; | ||
} |
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 { MigrationOptions } from '../../types'; | ||
import type { DropOptions } from '../generalTypes'; | ||
|
||
export type DropSchema = ( | ||
schemaName: string, | ||
dropOptions?: DropOptions | ||
) => string | string[]; | ||
|
||
export function dropSchema(mOptions: MigrationOptions): DropSchema { | ||
const _drop: DropSchema = (schemaName, options = {}) => { | ||
const { ifExists, cascade } = options; | ||
|
||
const ifExistsStr = ifExists ? ' IF EXISTS' : ''; | ||
const cascadeStr = cascade ? ' CASCADE' : ''; | ||
const schemaNameStr = mOptions.literal(schemaName); | ||
|
||
return `DROP SCHEMA${ifExistsStr} ${schemaNameStr}${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,3 @@ | ||
export * from './createSchema'; | ||
export * from './dropSchema'; | ||
export * from './renameSchema'; |
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,22 @@ | ||
import type { MigrationOptions } from '../../types'; | ||
|
||
export type RenameSchemaFn = ( | ||
oldSchemaName: string, | ||
newSchemaName: string | ||
) => string | string[]; | ||
|
||
export type RenameSchema = RenameSchemaFn & { reverse: RenameSchemaFn }; | ||
|
||
export function renameSchema(mOptions: MigrationOptions): RenameSchema { | ||
const _rename: RenameSchema = (schemaName, newSchemaName) => { | ||
const schemaNameStr = mOptions.literal(schemaName); | ||
const newSchemaNameStr = mOptions.literal(newSchemaName); | ||
|
||
return `ALTER SCHEMA ${schemaNameStr} RENAME TO ${newSchemaNameStr};`; | ||
}; | ||
|
||
_rename.reverse = (schemaName, newSchemaName) => | ||
_rename(newSchemaName, schemaName); | ||
|
||
return _rename; | ||
} |
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