Repository: salsita/node-pg-migrate
Pull request #519 (2019-11-25 13:58:31)

Refactored types


Patch:
diff --git a/.eslintrc.js b/.eslintrc.js
index dcfefbd..269367d 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -31,9 +31,7 @@ module.exports = {
     'no-underscore-dangle': 0,
     'security/detect-object-injection': 0,
     '@typescript-eslint/explicit-function-return-type': 0,
-    'import/no-cycle': 0,
     '@typescript-eslint/no-explicit-any': 0,
-    'import/no-duplicates': 0,
   },
   overrides: [
     {
diff --git a/bin/node-pg-migrate b/bin/node-pg-migrate
index e12015b..7eaf083 100755
--- a/bin/node-pg-migrate
+++ b/bin/node-pg-migrate
@@ -7,9 +7,7 @@ const util = require('util')
 const path = require('path')
 const yargs = require('yargs')
 const ConnectionParameters = require('pg/lib/connection-parameters')
-const migrationRunner = require('../index')
-
-const { Migration } = migrationRunner
+const { default: migrationRunner, Migration } = require('../dist')
 
 process.on('uncaughtException', err => {
   console.log(err.stack)
diff --git a/index.d.ts b/index.d.ts
deleted file mode 100644
index 09af40c..0000000
--- a/index.d.ts
+++ /dev/null
@@ -1,585 +0,0 @@
-// Type definitions for node-pg-migrate
-// Project: https://github.com/salsita/node-pg-migrate
-// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
-// Definitions by: Sam Grönblom <https://github.com/sgronblo>
-// Definitions by: Jan Doležel <https://github.com/dolezel>
-// Definitions by: Christopher Quadflieg <https://github.com/Shinigami92>
-
-type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });
-
-interface ValueArray extends Array<Value> {}
-
-export type Value = null | boolean | string | number | PgLiteral | ValueArray
-
-export type Name = string | { schema?: string, name: string }
-
-export type Type = string | { type: string }
-
-export type Action = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT'
-
-export interface ReferencesOptions {
-    referencesConstraintName?: string
-    referencesConstraintComment?: string
-    references?: Name
-    onDelete?: Action
-    onUpdate?: Action
-    match?: 'FULL' | 'SIMPLE'
-}
-
-export interface ForeignKeyOptions extends ReferencesOptions {
-    columns: Name | Name[]
-}
-
-export interface ConstraintOptions {
-    check?: string | string[]
-    unique?: Name | Array<Name | Name[]>
-    primaryKey?: Name | Name[]
-    foreignKeys?: ForeignKeyOptions | ForeignKeyOptions[]
-    exclude?: string
-    deferrable?: boolean
-    deferred?: boolean
-    comment?: string
-}
-
-export interface ColumnDefinition extends ReferencesOptions {
-    type: string
-    collation?: string
-    unique?: boolean
-    primaryKey?: boolean
-    notNull?: boolean
-    default?: Value
-    check?: string
-    deferrable?: boolean
-    deferred?: boolean
-    comment?: string | null
-    generated?: { precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions
-}
-
-export type Like = 'COMMENTS' | 'CONSTRAINTS' | 'DEFAULTS' | 'IDENTITY' | 'INDEXES' | 'STATISTICS' | 'STORAGE' | 'ALL'
-
-export interface LikeOptions {
-    including?: Like | Like[]
-    excluding?: Like | Like[]
-}
-
-export interface TableOptions {
-    temporary?: boolean
-    ifNotExists?: boolean
-    inherits?: Name
-    like?: Name | { table: Name, options?: LikeOptions }
-    constraints?: ConstraintOptions
-    comment?: string | null
-}
-
-export interface AlterColumnOptions {
-    type?: string
-    default?: Value
-    notNull?: boolean
-    allowNull?: boolean
-    collation?: string
-    using?: string
-    comment?: string | null
-    generated?: null | false | ({ precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions)
-}
-
-export interface CreateIndexOptions {
-    name?: string
-    unique?: boolean
-    where?: string
-    concurrently?: boolean
-    opclass?: string
-    method?: 'btree' | 'hash' | 'gist' | 'spgist' | 'gin'
-}
-
-export type Extension =
-	| 'adminpack'
-	| 'amcheck'
-	| 'auth_delay'
-	| 'auto_explain'
-	| 'bloom'
-	| 'btree_gin'
-	| 'btree_gist'
-	| 'citext'
-	| 'cube'
-	| 'dblink'
-	| 'dict_int'
-	| 'dict_xsyn'
-	| 'earthdistance'
-	| 'file_fdw'
-	| 'fuzzystrmatch'
-	| 'hstore'
-	| 'intagg'
-	| 'intarray'
-	| 'isn'
-	| 'lo'
-	| 'ltree'
-	| 'pageinspect'
-	| 'passwordcheck'
-	| 'pg_buffercache'
-	| 'pgcrypto'
-	| 'pg_freespacemap'
-	| 'pg_prewarm'
-	| 'pgrowlocks'
-	| 'pg_stat_statements'
-	| 'pgstattuple'
-	| 'pg_trgm'
-	| 'pg_visibility'
-	| 'postgres_fdw'
-	| 'seg'
-	| 'sepgsql'
-	| 'spi'
-	| 'sslinfo'
-	| 'tablefunc'
-	| 'tcn'
-	| 'test_decoding'
-	| 'tsm_system_rows'
-	| 'tsm_system_time'
-	| 'unaccent'
-	| 'uuid-ossp'
-	| 'xml2';
-
-export interface CreateExtensionOptions {
-    ifNotExists?: boolean
-    schema?: string
-}
-
-export interface ColumnDefinitions {
-    [name: string]: ColumnDefinition | string
-}
-
-export interface AlterTableOptions {
-    levelSecurity: 'DISABLE' | 'ENABLE' | 'FORCE' | 'NO FORCE'
-}
-
-// Note these currently don't contain the parameterized types like
-// bit(n), varchar(n) and so on, they have to be specified as strings
-export enum PgType {
-    BIGINT = 'bigint', // signed eight-byte integer
-    INT8 = 'int8', // alias for bigint
-    BIGSERIAL = 'bigserial', // autoincrementing eight-byte integer
-    BIT_1 = 'bit', // fixed-length bit string
-    BIT_VARYING = 'bit varying', // variable-length bit string
-    VARBIT = 'varbit', // alias for bit varying
-    SERIAL8 = 'serial8', // alias for bigserial
-    BOOLEAN = 'boolean', // logical Boolean (true/false)
-    BOOL = 'bool', // alias for boolean
-    BOX = 'box', // rectangular box on a plane
-    BYTEA = 'bytea', // binary data ("byte array")
-    CHARACTER = 'character', // fixed-length character string
-    CHAR = 'char', // alias for character
-    CHARACTER_VARYING = 'character varying', // variable-length character string
-    VARCHAR = 'varchar', // alias for character varying
-    CIDR = 'cidr', // IPv4 or IPv6 network address
-    CIRCLE = 'circle', // circle on a plane
-    DATE = 'date', // calendar date (year, month, day)
-    DOUBLE_PRECISION = 'double precision', // float8	double precision floating-point number (8 bytes)
-    INET = 'inet', // IPv4 or IPv6 host address
-    INTEGER = 'integer', // signed four-byte integer
-    INT = 'int', // alias for int
-    INT4 = 'int4', // alias for int
-    INTERVAL = 'interval', // time span
-    JSON = 'json', // textual JSON data
-    JSONB = 'jsonb', // binary JSON data, decomposed
-    LINE = 'line', // infinite line on a plane
-    LSEG = 'lseg', // line segment on a plane
-    MACADDR = 'macaddr', // MAC (Media Access Control) address
-    MONEY = 'money', // currency amount
-    NUMERIC = 'numeric', // exact numeric of selectable precision
-    PATH = 'path', // geometric path on a plane
-    PG_LSN = 'pg_lsn', // PostgreSQL Log Sequence Number
-    POINT = 'point', // geometric point on a plane
-    POLYGON = 'polygon', // closed geometric path on a plane
-    REAL = 'real', // single precision floating-point number (4 bytes)
-    FLOAT4 = 'float4', // alias for REAL
-    SMALLINT = 'smallint', // signed two-byte integer
-    INT2 = 'int2', // alias for smallint
-    SMALLSERIAL = 'smallserial', // autoincrementing two-byte integer
-    SERIAL2 = 'serial2', // alias for smallserial
-    SERIAL = 'serial', // autoincrementing four-byte integer
-    SERIAL4 = 'serial4', // alias for serial
-    TEXT = 'text', // variable-length character string
-    TIME = 'time', // time of day (no time zone)
-    TIME_WITHOUT_TIME_ZONE = 'without time zone', // alias of time
-    TIME_WITH_TIME_ZONE = 'time with time zone', // time of day, including time zone
-    TIMETZ = 'timetz', // alias of time with time zone
-    TIMESTAMP = 'timestamp', // date and time (no time zone)
-    TIMESTAMP_WITHOUT_TIME_ZONE = 'timestamp without time zone', // alias of timestamp
-    TIMESTAMP_WITH_TIME_ZONE = 'timestamp with time zone', // date and time, including time zone
-    TIMESTAMPTZ = 'timestamptz', // alias of timestamp with time zone
-    TSQUERY = 'tsquery', // text search query
-    TSVECTOR = 'tsvector', // text search document
-    TXID_SNAPSHOT = 'txid_snapshot', // user-level transaction ID snapshot
-    UUID = 'uuid', // universally unique identifier
-    XML = 'xml', // XML data
-}
-
-export interface RoleOptions {
-    superuser?: boolean
-    createdb?: boolean
-    createrole?: boolean
-    inherit?: boolean
-    login?: boolean
-    replication?: boolean
-    bypassrls?: boolean
-    limit?: number
-    password?: Value
-    encrypted?: boolean
-    valid?: Value
-    inRole?: string | string[]
-    role?: string | string[]
-    admin?: string | string[]
-}
-
-export interface IfExistsOption {
-    ifExists?: boolean
-}
-
-export interface IfNotExistsOption {
-    ifNotExists?: boolean
-}
-
-export interface CascadeOption {
-    cascade?: boolean
-}
-
-export type AddOptions = IfNotExistsOption
-export type DropOptions = IfExistsOption & CascadeOption
-
-interface DropIndexOptionsEn {
-    name?: string
-    concurrently?: boolean
-}
-
-export type DropIndexOptions = DropIndexOptionsEn & DropOptions
-
-export interface FunctionParamType {
-    mode?: 'IN' | 'OUT' | 'INOUT' | 'VARIADIC'
-    name?: string
-    type: string
-    default?: Value
-}
-
-export type FunctionParam = string | FunctionParamType
-
-export interface FunctionOptions {
-    returns?: string
-    language: string
-    replace?: boolean
-    window?: boolean
-    behavior?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
-    onNull?: boolean
-    parallel?: 'UNSAFE' | 'RESTRICTED' | 'SAFE'
-}
-
-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
-}
-
-interface DomainOptions {
-    default?: Value
-    notNull?: boolean
-    check?: string
-    constraintName?: string
-}
-
-interface DomainOptionsCreateEn {
-    collation?: string
-}
-
-interface DomainOptionsAlterEn {
-    allowNull?: boolean
-}
-
-export type DomainOptionsCreate = DomainOptionsCreateEn & DomainOptions
-
-export type DomainOptionsAlter = DomainOptionsAlterEn & DomainOptions
-
-interface SequenceOptions {
-    type?: Type
-    increment?: number
-    minvalue?: number | null | false
-    maxvalue?: number | null | false
-    start?: number
-    cache?: number
-    cycle?: boolean
-    owner?: string | null | false
-}
-
-interface SequenceOptionsCreateEn {
-    temporary?: boolean
-    ifNotExists?: boolean
-}
-
-interface SequenceOptionsAlterEn {
-    restart?: number | true
-}
-
-export type SequenceOptionsCreate = SequenceOptionsCreateEn & SequenceOptions
-
-export type SequenceOptionsAlter = SequenceOptionsAlterEn & SequenceOptions
-
-export interface CreateOperatorOptions {
-    procedure: Name
-    left?: Name
-    right?: Name
-    commutator?: Name
-    negator?: Name
-    restrict?: Name
-    join?: Name
-    hashes?: boolean
-    merges?: boolean
-}
-
-export interface DropOperatorOptions {
-    left?: Name
-    right?: Name
-    ifExists?: boolean
-    cascade?: boolean
-}
-
-export interface CreateOperatorClassOptions {
-    default?: boolean
-    family?: string
-}
-
-export interface OperatorListDefinition {
-    type: 'function' | 'operator'
-    number: number
-    name: Name
-    params?: FunctionParam[]
-}
-
-export interface PolicyOptions {
-    role: string | string[]
-    using: string
-    check: string
-}
-
-export interface CreatePolicyOptionsEn {
-    command: 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE'
-}
-
-export type CreatePolicyOptions = CreatePolicyOptionsEn & PolicyOptions
-
-export interface CreateViewOptions {
-    temporary?: boolean
-    replace?: boolean
-    recursive?: boolean
-    columns?: string | string[]
-    checkOption?: 'CASCADED' | 'LOCAL'
-}
-
-export interface AlterViewOptions {
-    checkOption?: null | false | 'CASCADED' | 'LOCAL'
-}
-
-export interface AlterViewColumnOptions {
-    default?: Value
-}
-
-export interface CreateMaterializedViewOptions {
-    ifNotExists?: boolean
-    columns?: string | string[]
-    tablespace?: string
-    storageParameters?: object
-    data?: boolean
-}
-
-export interface AlterMaterializedViewOptions {
-    cluster?: null | false | string
-    extension?: string
-    storageParameters?: object
-}
-
-export interface RefreshMaterializedViewOptions {
-    concurrently?: boolean
-    data?: boolean
-}
-
-import { QueryConfig, QueryResult, Client } from "pg";
-
-// see ClientBase in @types/pg
-interface DB {
-    query(queryConfig: QueryConfig): Promise<QueryResult>;
-    query(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<QueryResult>;
-
-    select(queryConfig: QueryConfig): Promise<any[]>;
-    select(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>;
-}
-
-export interface MigrationBuilder {
-    // Tables
-    createTable(tableName: Name, columns: ColumnDefinitions, options?: TableOptions): void
-    dropTable(tableName: Name, dropOptions?: DropOptions): void
-    renameTable(tableName: Name, newtableName: Name): void
-    alterTable(tableName: Name, alterOptions: AlterTableOptions): void
-
-    // Columns
-    addColumns(tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions): void
-    addColumn(tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions): void
-    dropColumns(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions?: DropOptions): void
-    dropColumn(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions?: DropOptions): void
-    renameColumn(tableName: Name, oldColumnName: string, newColumnName: string): void
-    alterColumn(tableName: Name, columnName: string, options: AlterColumnOptions): void
-
-    // Constraints
-    addConstraint(tableName: Name, constraintName: string | null, expression: string | ConstraintOptions): void
-    createConstraint(tableName: Name, constraintName: string | null, expression: string | ConstraintOptions): void
-    dropConstraint(tableName: Name, constraintName: string, options?: DropOptions): void
-    renameConstraint(tableName: Name, oldConstraintName: string, newConstraintName: string): void
-
-    // Indexes
-    createIndex(tableName: Name, columns: string | string[], options?: CreateIndexOptions): void
-    addIndex(tableName: Name, columns: string | string[], options?: CreateIndexOptions): void
-    dropIndex(tableName: Name, columns: string | string[], options?: DropIndexOptions): void
-
-    // Extensions
-    createExtension(extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>, options?: CreateExtensionOptions): void
-    addExtension(extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>, options?: CreateExtensionOptions): void
-    dropExtension(extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>, dropOptions?: DropOptions): void
-
-    // Types
-    createType(typeName: Name, values: Value[] | { [name: string]: Type }): void
-    addType(typeName: Name, values: Value[] | { [name: string]: Type }): void
-    dropType(typeName: Name, dropOptions?: DropOptions): void
-    renameType(typeName: Name, newTypeName: Name): void
-    addTypeAttribute(typeName: Name, attributeName: string, attributeType: Type): void
-    dropTypeAttribute(typeName: Name, attributeName: string, options: IfExistsOption): void
-    setTypeAttribute(typeName: Name, attributeName: string, attributeType: Type): void
-    addTypeValue(typeName: Name, value: Value, options?: { ifNotExists?: boolean, before?: string, after?: string }): void
-    renameTypeAttribute(typeName: Name, attributeName: string, newAttributeName: string): void
-    renameTypeValue(typeName: Name, value: string, newValue: string): void
-
-    // Roles
-    createRole(roleName: Name, roleOptions?: RoleOptions): void
-    dropRole(roleName: Name, options?: IfExistsOption): void
-    alterRole(roleName: Name, roleOptions: RoleOptions): void
-    renameRole(oldRoleName: Name, newRoleName: Name): void
-
-    // Functions
-    createFunction(functionName: Name, functionParams: FunctionParam[], functionOptions: FunctionOptions, definition: Value): void
-    dropFunction(functionName: Name, functionParams: FunctionParam[], dropOptions?: DropOptions): void
-    renameFunction(oldFunctionName: Name, functionParams: FunctionParam[], newFunctionName: Name): void
-
-    // Triggers
-    createTrigger(tableName: Name, triggerName: string, triggerOptions: TriggerOptions): void
-    createTrigger(tableName: Name, triggerName: string, triggerOptions: TriggerOptions & FunctionOptions, definition: Value): void
-    dropTrigger(tableName: Name, triggerName: string, dropOptions?: DropOptions): void
-    renameTrigger(tableName: Name, oldTriggerName: string, newTriggerName: string): void
-
-    // Schemas
-    createSchema(schemaName: string, schemaOptions?: { ifNotExists?: boolean, authorization?: string }): void
-    dropSchema(schemaName: string, dropOptions?: DropOptions): void
-    renameSchema(oldSchemaName: string, newSchemaName: string): void
-
-    // Domains
-    createDomain(domainName: Name, type: Type, domainOptions?: DomainOptionsCreate): void
-    dropDomain(domainName: Name, dropOptions?: DropOptions): void
-    alterDomain(domainName: Name, domainOptions: DomainOptionsAlter): void
-    renameDomain(oldDomainName: Name, newDomainName: Name): void
-
-    // Sequences
-    createSequence(sequenceName: Name, sequenceOptions?: SequenceOptionsCreate): void
-    dropSequence(sequenceName: Name, dropOptions?: DropOptions): void
-    alterSequence(sequenceName: Name, sequenceOptions: SequenceOptionsAlter): void
-    renameSequence(oldSequenceName: Name, newSequenceName: Name): void
-
-    // Operators
-    createOperator(operatorName: Name, options?: CreateOperatorOptions): void
-    dropOperator(operatorName: Name, dropOptions?: DropOperatorOptions): void
-    createOperatorClass(operatorClassName: Name, type: Type, indexMethod: Name, operatorList: OperatorListDefinition, options: CreateOperatorClassOptions): void
-    dropOperatorClass(operatorClassName: Name, indexMethod: Name, dropOptions?: DropOptions): void
-    renameOperatorClass(oldOperatorClassName: Name, indexMethod: Name, newOperatorClassName: Name): void
-    createOperatorFamily(operatorFamilyName: Name, indexMethod: Name): void
-    dropOperatorFamily(operatorFamilyName: Name, newSchemaName: Name, dropOptions?: DropOptions): void
-    renameOperatorFamily(oldOperatorFamilyName: Name, indexMethod: Name, newOperatorFamilyName: Name): void
-    addToOperatorFamily(operatorFamilyName: Name, indexMethod: Name, operatorList: OperatorListDefinition): void
-    removeFromOperatorFamily(operatorFamilyName: Name, indexMethod: Name, operatorList: OperatorListDefinition): void
-
-    // Policies
-    createPolicy(tableName: Name, policyName: string, options?: CreatePolicyOptions): void
-    dropPolicy(tableName: Name, policyName: string, options?: IfExistsOption): void
-    alterPolicy(tableName: Name, policyName: string, options: PolicyOptions): void
-    renamePolicy(tableName: Name, policyName: string, newPolicyName: string): void
-
-    createView(viewName: Name, options: CreateViewOptions, definition: string): void
-    dropView(viewName: Name, options?: DropOptions): void
-    alterView(viewName: Name, options: AlterViewOptions): void
-    alterViewColumn(viewName: Name, columnName: string, options: AlterViewColumnOptions): void
-    renameView(viewName: Name, newViewName: Name): void
-
-    createMaterializedView(viewName: Name, options: CreateMaterializedViewOptions, definition: string): void
-    dropMaterializedView(viewName: Name, options?: DropOptions): void
-    alterMaterializedView(viewName: Name, options: AlterMaterializedViewOptions): void
-    renameMaterializedView(viewName: Name, newViewName: Name): void
-    renameMaterializedViewColumn(viewName: Name, columnName: string, newColumnName: string): void
-    refreshMaterializedView(viewName: Name, options?: RefreshMaterializedViewOptions): void
-
-    sql(sql: string, args?: object): void
-    func(sql: string): PgLiteral
-    noTransaction(): void
-
-    db: DB
-}
-
-export class PgLiteral {
-    static create(str: string): PgLiteral
-    constructor(str: string)
-    toString(): string
-}
-
-export interface ConnectionConfig {
-    user?: string;
-    database?: string;
-    password?: string;
-    port?: number;
-    host?: string;
-    connectionString?: string;
-}
-
-import { TlsOptions } from "tls";
-
-export interface ClientConfig extends ConnectionConfig {
-    ssl?: boolean | TlsOptions;
-}
-
-export interface RunnerOptionUrl {
-    databaseUrl: string | ClientConfig
-}
-
-export interface RunnerOptionClient {
-    dbClient: Client
-}
-
-export interface RunnerOptionConfig {
-    migrationsTable: string
-    migrationsSchema?: string
-    schema?: string | string[]
-    dir: string
-    checkOrder?: boolean
-    direction: 'up' | 'down'
-    count: number
-    timestamp?: boolean
-    ignorePattern: string
-    file?: string
-    dryRun?: boolean
-    createSchema?: boolean
-    createMigrationsSchema?: boolean
-    singleTransaction?: boolean
-    noLock?: boolean,
-    fake?: boolean,
-    decamelize?: boolean,
-    log?: (msg:string) => void;
-}
-
-export type RunnerOption = RunnerOptionConfig & (RunnerOptionClient | RunnerOptionUrl)
-
-export default function (options: RunnerOption): Promise<void>
diff --git a/index.js b/index.js
deleted file mode 100644
index c4213d6..0000000
--- a/index.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const runner = require('./dist/runner')
-const definitions = require('./dist/definitions')
-
-module.exports = runner.default
-module.exports.default = runner.default
-module.exports.PgLiteral = runner.PgLiteral
-module.exports.Migration = runner.Migration
-module.exports.PgType = definitions.PgType
diff --git a/package.json b/package.json
index 8777729..632c399 100644
--- a/package.json
+++ b/package.json
@@ -7,8 +7,8 @@
   "bin": {
     "node-pg-migrate": "bin/node-pg-migrate"
   },
-  "main": "index.js",
-  "types": "index.d.ts",
+  "main": "dist/index.js",
+  "types": "dist/index.d.ts",
   "keywords": [
     "db",
     "database",
diff --git a/src/db.ts b/src/db.ts
index 8e74704..aa7e806 100644
--- a/src/db.ts
+++ b/src/db.ts
@@ -8,25 +8,27 @@ import { Client, ClientConfig, QueryArrayResult, QueryResult, QueryArrayConfig,
 
 // see ClientBase in @types/pg
 export interface DB {
-  createConnection(): Promise<void>
-
   query(queryConfig: QueryArrayConfig, values?: any[]): Promise<QueryArrayResult>
   query(queryConfig: QueryConfig): Promise<QueryResult>
   query(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<QueryResult>
 
-  select(queryConfig: QueryArrayConfig, values?: any[]): Promise<any[][]>
-  select(queryConfig: QueryConfig): Promise<any[][]>
-  select(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[][]>
+  select(queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>
+  select(queryConfig: QueryConfig): Promise<any[]>
+  select(queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>
+}
+
+export interface DBConnection extends DB {
+  createConnection(): Promise<void>
 
-  column(columnName: 'name', queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>
-  column(columnName: 'name', queryConfig: QueryConfig): Promise<any[]>
-  column(columnName: 'name', queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>
+  column(columnName: string, queryConfig: QueryArrayConfig, values?: any[]): Promise<any[]>
+  column(columnName: string, queryConfig: QueryConfig): Promise<any[]>
+  column(columnName: string, queryTextOrConfig: string | QueryConfig, values?: any[]): Promise<any[]>
 
   addBeforeCloseListener: (listener: any) => number
   close(): Promise<void>
 }
 
-const db = (connection: Client | string | ClientConfig, log = console.error): DB => {
+const db = (connection: Client | string | ClientConfig, log = console.error): DBConnection => {
   const isExternalClient = connection instanceof Client
   let clientActive = false
 
@@ -48,7 +50,7 @@ const db = (connection: Client | string | ClientConfig, log = console.error): DB
           }),
     )
 
-  const query: DB['query'] = async (
+  const query: DBConnection['query'] = async (
     queryTextOrConfig: string | QueryConfig | QueryArrayConfig,
     values?: any[],
   ): Promise<QueryArrayResult | QueryResult> => {
@@ -81,11 +83,14 @@ ${err}
     }
   }
 
-  const select: DB['select'] = async (queryTextOrConfig: string | QueryConfig | QueryArrayConfig, values?: any[]) => {
+  const select: DBConnection['select'] = async (
+    queryTextOrConfig: string | QueryConfig | QueryArrayConfig,
+    values?: any[],
+  ) => {
     const { rows } = await query(queryTextOrConfig, values)
     return rows
   }
-  const column: DB['column'] = async (
+  const column: DBConnection['column'] = async (
     columnName: string,
     queryTextOrConfig: string | QueryConfig | QueryArrayConfig,
     values?: any[],
diff --git a/src/definitions.ts b/src/definitions.ts
deleted file mode 100644
index e451277..0000000
--- a/src/definitions.ts
+++ /dev/null
@@ -1,123 +0,0 @@
-import { PgLiteral } from './utils'
-import { SequenceOptions } from './operations/sequences'
-
-export type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never })
-
-export type Value = null | boolean | string | number | PgLiteral | Value[]
-
-export type Type = string | { type: string }
-
-export type Name = string | { schema?: string; name: string }
-
-export type Action = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT'
-
-// Note these currently don't contain the parameterized types like
-// bit(n), varchar(n) and so on, they have to be specified as strings
-export enum PgType { // eslint-disable-line import/prefer-default-export
-  BIGINT = 'bigint', // signed eight-byte integer
-  INT8 = 'int8', // alias for bigint
-  BIGSERIAL = 'bigserial', // autoincrementing eight-byte integer
-  BIT_1 = 'bit', // fixed-length bit string
-  BIT_VARYING = 'bit varying', // variable-length bit string
-  VARBIT = 'varbit', // alias for bit varying
-  SERIAL8 = 'serial8', // alias for bigserial
-  BOOLEAN = 'boolean', // logical Boolean (true/false)
-  BOOL = 'bool', // alias for boolean
-  BOX = 'box', // rectangular box on a plane
-  BYTEA = 'bytea', // binary data ("byte array")
-  CHARACTER = 'character', // fixed-length character string
-  CHAR = 'char', // alias for character
-  CHARACTER_VARYING = 'character varying', // variable-length character string
-  VARCHAR = 'varchar', // alias for character varying
-  CIDR = 'cidr', // IPv4 or IPv6 network address
-  CIRCLE = 'circle', // circle on a plane
-  DATE = 'date', // calendar date (year, month, day)
-  DOUBLE_PRECISION = 'double precision', // float8	double precision floating-point number (8 bytes)
-  INET = 'inet', // IPv4 or IPv6 host address
-  INTEGER = 'integer', // signed four-byte integer
-  INT = 'int', // alias for int
-  INT4 = 'int4', // alias for int
-  INTERVAL = 'interval', // time span
-  JSON = 'json', // textual JSON data
-  JSONB = 'jsonb', // binary JSON data, decomposed
-  LINE = 'line', // infinite line on a plane
-  LSEG = 'lseg', // line segment on a plane
-  MACADDR = 'macaddr', // MAC (Media Access Control) address
-  MONEY = 'money', // currency amount
-  NUMERIC = 'numeric', // exact numeric of selectable precision
-  PATH = 'path', // geometric path on a plane
-  PG_LSN = 'pg_lsn', // PostgreSQL Log Sequence Number
-  POINT = 'point', // geometric point on a plane
-  POLYGON = 'polygon', // closed geometric path on a plane
-  REAL = 'real', // single precision floating-point number (4 bytes)
-  FLOAT4 = 'float4', // alias for REAL
-  SMALLINT = 'smallint', // signed two-byte integer
-  INT2 = 'int2', // alias for smallint
-  SMALLSERIAL = 'smallserial', // autoincrementing two-byte integer
-  SERIAL2 = 'serial2', // alias for smallserial
-  SERIAL = 'serial', // autoincrementing four-byte integer
-  SERIAL4 = 'serial4', // alias for serial
-  TEXT = 'text', // variable-length character string
-  TIME = 'time', // time of day (no time zone)
-  TIME_WITHOUT_TIME_ZONE = 'without time zone', // alias of time
-  TIME_WITH_TIME_ZONE = 'time with time zone', // time of day, including time zone
-  TIMETZ = 'timetz', // alias of time with time zone
-  TIMESTAMP = 'timestamp', // date and time (no time zone)
-  TIMESTAMP_WITHOUT_TIME_ZONE = 'timestamp without time zone', // alias of timestamp
-  TIMESTAMP_WITH_TIME_ZONE = 'timestamp with time zone', // date and time, including time zone
-  TIMESTAMPTZ = 'timestamptz', // alias of timestamp with time zone
-  TSQUERY = 'tsquery', // text search query
-  TSVECTOR = 'tsvector', // text search document
-  TXID_SNAPSHOT = 'txid_snapshot', // user-level transaction ID snapshot
-  UUID = 'uuid', // universally unique identifier
-  XML = 'xml', // XML data
-}
-
-export interface ReferencesOptions {
-  referencesConstraintName?: string
-  referencesConstraintComment?: string
-  references?: Name
-  onDelete?: Action
-  onUpdate?: Action
-  match?: 'FULL' | 'SIMPLE'
-}
-
-export interface ColumnDefinition extends ReferencesOptions {
-  type: string
-  collation?: string
-  unique?: boolean
-  primaryKey?: boolean
-  notNull?: boolean
-  default?: Value
-  check?: string
-  deferrable?: boolean
-  deferred?: boolean
-  comment?: string | null
-  generated?: { precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions
-}
-
-export interface ColumnDefinitions {
-  [name: string]: ColumnDefinition | string
-}
-
-export type Like = 'COMMENTS' | 'CONSTRAINTS' | 'DEFAULTS' | 'IDENTITY' | 'INDEXES' | 'STATISTICS' | 'STORAGE' | 'ALL'
-
-export interface LikeOptions {
-  including?: Like | Like[]
-  excluding?: Like | Like[]
-}
-
-export interface IfNotExistsOption {
-  ifNotExists?: boolean
-}
-
-export interface IfExistsOption {
-  ifExists?: boolean
-}
-
-export interface CascadeOption {
-  cascade?: boolean
-}
-
-export type AddOptions = IfNotExistsOption
-export type DropOptions = IfExistsOption & CascadeOption
diff --git a/src/index.ts b/src/index.ts
new file mode 100644
index 0000000..bfd8e0d
--- /dev/null
+++ b/src/index.ts
@@ -0,0 +1,235 @@
+import runner from './runner'
+import { Migration } from './migration'
+import { RunnerOption, MigrationBuilder, PgType } from './types'
+import PgLiteral from './operations/PgLiteral'
+import {
+  Value,
+  Name,
+  Type,
+  IfExistsOption,
+  IfNotExistsOption,
+  CascadeOption,
+  DropOptions,
+} from './operations/generalTypes'
+import {
+  CreateDomain,
+  DropDomain,
+  AlterDomain,
+  RenameDomain,
+  DomainOptionsCreate,
+  DomainOptionsAlter,
+} from './operations/domainsTypes'
+import { CreateExtension, DropExtension, Extension, CreateExtensionOptions } from './operations/extensionsTypes'
+import {
+  CreateFunction,
+  DropFunction,
+  RenameFunction,
+  FunctionParam,
+  FunctionOptions,
+} from './operations/functionsTypes'
+import { DropIndex, CreateIndex, CreateIndexOptions, DropIndexOptions } from './operations/indexesTypes'
+import {
+  CreateOperator,
+  DropOperator,
+  CreateOperatorClass,
+  DropOperatorClass,
+  CreateOperatorFamily,
+  DropOperatorFamily,
+  AddToOperatorFamily,
+  RenameOperatorFamily,
+  RenameOperatorClass,
+  RemoveFromOperatorFamily,
+  CreateOperatorOptions,
+  DropOperatorOptions,
+  OperatorListDefinition,
+  CreateOperatorClassOptions,
+} from './operations/operatorsTypes'
+import { Sql } from './operations/othersTypes'
+import {
+  CreatePolicy,
+  DropPolicy,
+  AlterPolicy,
+  RenamePolicy,
+  CreatePolicyOptions,
+  PolicyOptions,
+} from './operations/policiesTypes'
+import { CreateRole, DropRole, AlterRole, RenameRole, RoleOptions } from './operations/rolesTypes'
+import {
+  CreateSequence,
+  DropSequence,
+  AlterSequence,
+  RenameSequence,
+  SequenceOptionsCreate,
+  SequenceOptionsAlter,
+} from './operations/sequencesTypes'
+import { CreateSchema, DropSchema, RenameSchema, CreateSchemaOptions } from './operations/schemasTypes'
+import {
+  CreateTable,
+  DropTable,
+  AlterTable,
+  RenameTable,
+  AddColumns,
+  DropColumns,
+  AlterColumn,
+  RenameColumn,
+  CreateConstraint,
+  DropConstraint,
+  RenameConstraint,
+  ColumnDefinitions,
+  TableOptions,
+  AlterTableOptions,
+  AlterColumnOptions,
+  ConstraintOptions,
+} from './operations/tablesTypes'
+import { CreateTrigger, DropTrigger, RenameTrigger, TriggerOptions } from './operations/triggersTypes'
+import {
+  CreateType,
+  DropType,
+  RenameType,
+  AddTypeAttribute,
+  DropTypeAttribute,
+  SetTypeAttribute,
+  AddTypeValue,
+  RenameTypeAttribute,
+  RenameTypeValue,
+  AddTypeValueOptions,
+} from './operations/typesTypes'
+import {
+  CreateView,
+  DropView,
+  AlterView,
+  AlterViewColumn,
+  RenameView,
+  CreateViewOptions,
+  AlterViewOptions,
+  AlterViewColumnOptions,
+} from './operations/viewsTypes'
+import {
+  CreateMaterializedView,
+  DropMaterializedView,
+  AlterMaterializedView,
+  RenameMaterializedView,
+  RenameMaterializedViewColumn,
+  RefreshMaterializedView,
+  CreateMaterializedViewOptions,
+  AlterMaterializedViewOptions,
+  RefreshMaterializedViewOptions,
+} from './operations/viewsMaterializedTypes'
+
+export {
+  PgLiteral,
+  Migration,
+  PgType,
+  MigrationBuilder,
+  RunnerOption,
+  Value,
+  Name,
+  Type,
+  IfExistsOption,
+  IfNotExistsOption,
+  CascadeOption,
+  DropOptions,
+  CreateTable,
+  DropTable,
+  AlterTable,
+  RenameTable,
+  AddColumns,
+  DropColumns,
+  AlterColumn,
+  RenameColumn,
+  CreateConstraint,
+  DropConstraint,
+  RenameConstraint,
+  ColumnDefinitions,
+  TableOptions,
+  AlterTableOptions,
+  AlterColumnOptions,
+  ConstraintOptions,
+  CreateDomain,
+  DropDomain,
+  AlterDomain,
+  RenameDomain,
+  DomainOptionsCreate,
+  DomainOptionsAlter,
+  CreateExtension,
+  DropExtension,
+  Extension,
+  CreateExtensionOptions,
+  CreateFunction,
+  DropFunction,
+  RenameFunction,
+  FunctionParam,
+  FunctionOptions,
+  DropIndex,
+  CreateIndex,
+  CreateIndexOptions,
+  DropIndexOptions,
+  CreateOperator,
+  DropOperator,
+  CreateOperatorClass,
+  DropOperatorClass,
+  RenameOperatorClass,
+  CreateOperatorFamily,
+  DropOperatorFamily,
+  AddToOperatorFamily,
+  RenameOperatorFamily,
+  RemoveFromOperatorFamily,
+  CreateOperatorOptions,
+  DropOperatorOptions,
+  OperatorListDefinition,
+  CreateOperatorClassOptions,
+  Sql,
+  CreatePolicy,
+  DropPolicy,
+  AlterPolicy,
+  RenamePolicy,
+  CreatePolicyOptions,
+  PolicyOptions,
+  CreateRole,
+  DropRole,
+  AlterRole,
+  RenameRole,
+  RoleOptions,
+  CreateSequence,
+  DropSequence,
+  AlterSequence,
+  RenameSequence,
+  SequenceOptionsCreate,
+  SequenceOptionsAlter,
+  CreateSchema,
+  DropSchema,
+  RenameSchema,
+  CreateSchemaOptions,
+  CreateTrigger,
+  DropTrigger,
+  RenameTrigger,
+  TriggerOptions,
+  CreateType,
+  DropType,
+  RenameType,
+  AddTypeAttribute,
+  DropTypeAttribute,
+  SetTypeAttribute,
+  AddTypeValue,
+  RenameTypeAttribute,
+  RenameTypeValue,
+  AddTypeValueOptions,
+  CreateView,
+  DropView,
+  AlterView,
+  AlterViewColumn,
+  RenameView,
+  CreateViewOptions,
+  AlterViewOptions,
+  AlterViewColumnOptions,
+  CreateMaterializedView,
+  DropMaterializedView,
+  AlterMaterializedView,
+  RenameMaterializedView,
+  RenameMaterializedViewColumn,
+  RefreshMaterializedView,
+  CreateMaterializedViewOptions,
+  AlterMaterializedViewOptions,
+  RefreshMaterializedViewOptions,
+}
+export default runner
diff --git a/src/migration-builder.ts b/src/migration-builder.ts
index 7f67c32..6eddddc 100644
--- a/src/migration-builder.ts
+++ b/src/migration-builder.ts
@@ -10,34 +10,9 @@
  */
 
 import { DB } from './db'
-import {
-  AddOptions,
-  ColumnDefinitions,
-  DropOptions,
-  IfExistsOption,
-  LiteralUnion,
-  Name,
-  Type,
-  Value,
-} from './definitions'
-import { DomainOptionsAlter, DomainOptionsCreate } from './operations/domains'
-import { CreateExtensionOptions, Extension } from './operations/extensions'
-import { FunctionOptions, FunctionParam } from './operations/functions'
-import { CreateIndexOptions, DropIndexOptions } from './operations/indexes'
-import {
-  CreateOperatorClassOptions,
-  CreateOperatorOptions,
-  DropOperatorOptions,
-  OperatorListDefinition,
-} from './operations/operators'
-import { CreatePolicyOptions, PolicyOptions } from './operations/policies'
-import { RoleOptions } from './operations/roles'
-import { CreateSchemaOptions } from './operations/schemas'
-import { SequenceOptionsAlter, SequenceOptionsCreate } from './operations/sequences'
-import { AlterColumnOptions, AlterTableOptions, ConstraintOptions, TableOptions } from './operations/tables'
-import { TriggerOptions } from './operations/triggers'
-import { AlterViewColumnOptions, AlterViewOptions, CreateViewOptions } from './operations/views'
-import { createSchemalize, PgLiteral } from './utils'
+import { createSchemalize } from './utils'
+import { ColumnDefinitions } from './operations/tablesTypes'
+import { MigrationBuilder, MigrationOptions } from './types'
 
 import * as domains from './operations/domains'
 import * as extensions from './operations/extensions'
@@ -54,255 +29,167 @@ import * as triggers from './operations/triggers'
 import * as types from './operations/types'
 import * as views from './operations/views'
 import * as mViews from './operations/viewsMaterialized'
-
-export type MigrationAction = (pgm: MigrationBuilder, run?: () => void) => Promise<void> | void
-
-export interface MigrationBuilderActions {
-  up?: MigrationAction
-  down?: MigrationAction
-  shorthands?: ColumnDefinitions
-}
-
-export interface MigrationOptions {
-  typeShorthands: ColumnDefinitions
-  schemalize: (v: Name) => string
-  literal: (v: Name) => string
-}
+import PgLiteral from './operations/PgLiteral'
 
 /* eslint-disable security/detect-non-literal-fs-filename */
-export default class MigrationBuilder {
-  public readonly createExtension: (
-    extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
-    options?: CreateExtensionOptions,
-  ) => void
+export default class MigrationBuilderImpl implements MigrationBuilder {
+  public readonly createExtension: (...args: Parameters<extensions.CreateExtension>) => void
 
-  public readonly dropExtension: (
-    extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
-    dropOptions?: DropOptions,
-  ) => void
+  public readonly dropExtension: (...args: Parameters<extensions.DropExtension>) => void
 
-  public readonly addExtension: (
-    extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
-    options?: CreateExtensionOptions,
-  ) => void
+  public readonly addExtension: (...args: Parameters<extensions.CreateExtension>) => void
 
-  public readonly createTable: (tableName: Name, columns: ColumnDefinitions, options?: TableOptions) => void
+  public readonly createTable: (...args: Parameters<tables.CreateTable>) => void
 
-  public readonly dropTable: (tableName: Name, dropOptions?: DropOptions) => void
+  public readonly dropTable: (...args: Parameters<tables.DropTable>) => void
 
-  public readonly renameTable: (tableName: Name, newtableName: Name) => void
+  public readonly renameTable: (...args: Parameters<tables.RenameTable>) => void
 
-  public readonly alterTable: (tableName: Name, alterOptions: AlterTableOptions) => void
+  public readonly alterTable: (...args: Parameters<tables.AlterTable>) => void
 
-  public readonly addColumns: (tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions) => void
+  public readonly addColumns: (...args: Parameters<tables.AddColumns>) => void
 
-  public readonly dropColumns: (
-    tableName: Name,
-    columns: string | string[] | { [name: string]: any },
-    dropOptions?: DropOptions,
-  ) => void
+  public readonly dropColumns: (...args: Parameters<tables.DropColumns>) => void
 
-  public readonly renameColumn: (tableName: Name, oldColumnName: string, newColumnName: string) => void
+  public readonly renameColumn: (...args: Parameters<tables.RenameColumn>) => void
 
-  public readonly alterColumn: (tableName: Name, columnName: string, options: AlterColumnOptions) => void
+  public readonly alterColumn: (...args: Parameters<tables.AlterColumn>) => void
 
-  public readonly addColumn: (tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions) => void
+  public readonly addColumn: (...args: Parameters<tables.AddColumns>) => void
 
-  public readonly dropColumn: (
-    tableName: Name,
-    columns: string | string[] | { [name: string]: any },
-    dropOptions?: DropOptions,
-  ) => void
+  public readonly dropColumn: (...args: Parameters<tables.DropColumns>) => void
 
-  public readonly addConstraint: (
-    tableName: Name,
-    constraintName: string | null,
-    expression: string | ConstraintOptions,
-  ) => void
+  public readonly addConstraint: (...args: Parameters<tables.CreateConstraint>) => void
 
-  public readonly dropConstraint: (tableName: Name, constraintName: string, options?: DropOptions) => void
+  public readonly dropConstraint: (...args: Parameters<tables.DropConstraint>) => void
 
-  public readonly renameConstraint: (tableName: Name, oldConstraintName: string, newConstraintName: string) => void
+  public readonly renameConstraint: (...args: Parameters<tables.RenameConstraint>) => void
 
-  public readonly createConstraint: (
-    tableName: Name,
-    constraintName: string | null,
-    expression: string | ConstraintOptions,
-  ) => void
+  public readonly createConstraint: (...args: Parameters<tables.CreateConstraint>) => void
 
-  public readonly createType: (typeName: Name, values: Value[] | { [name: string]: Type }) => void
+  public readonly createType: (...args: Parameters<types.CreateType>) => void
 
-  public readonly dropType: (typeName: Name, dropOptions?: DropOptions) => void
+  public readonly dropType: (...args: Parameters<types.DropType>) => void
 
-  public readonly addType: (typeName: Name, values: Value[] | { [name: string]: Type }) => void
+  public readonly addType: (...args: Parameters<types.CreateType>) => void
 
-  public readonly renameType: (typeName: Name, newTypeName: Name) => void
+  public readonly renameType: (...args: Parameters<types.RenameType>) => void
 
-  public readonly renameTypeAttribute: (typeName: Name, attributeName: string, newAttributeName: string) => void
+  public readonly renameTypeAttribute: (...args: Parameters<types.RenameTypeAttribute>) => void
 
-  public readonly renameTypeValue: (typeName: Name, value: string, newValue: string) => void
+  public readonly renameTypeValue: (...args: Parameters<types.RenameTypeValue>) => void
 
-  public readonly addTypeAttribute: (typeName: Name, attributeName: string, attributeType: Type) => void
+  public readonly addTypeAttribute: (...args: Parameters<types.AddTypeAttribute>) => void
 
-  public readonly dropTypeAttribute: (typeName: Name, attributeName: string, options: IfExistsOption) => void
+  public readonly dropTypeAttribute: (...args: Parameters<types.DropTypeAttribute>) => void
 
-  public readonly setTypeAttribute: (typeName: Name, attributeName: string, attributeType: Type) => void
+  public readonly setTypeAttribute: (...args: Parameters<types.SetTypeAttribute>) => void
 
-  public readonly addTypeValue: (
-    typeName: Name,
-    value: Value,
-    options?: {
-      ifNotExists?: boolean
-      before?: string
-      after?: string
-    },
-  ) => void
+  public readonly addTypeValue: (...args: Parameters<types.AddTypeValue>) => void
 
-  public readonly createIndex: (tableName: Name, columns: string | string[], options?: CreateIndexOptions) => void
+  public readonly createIndex: (...args: Parameters<indexes.CreateIndex>) => void
 
-  public readonly dropIndex: (tableName: Name, columns: string | string[], options?: DropIndexOptions) => void
+  public readonly dropIndex: (...args: Parameters<indexes.DropIndex>) => void
 
-  public readonly addIndex: (tableName: Name, columns: string | string[], options?: CreateIndexOptions) => void
+  public readonly addIndex: (...args: Parameters<indexes.CreateIndex>) => void
 
-  public readonly createRole: (roleName: Name, roleOptions?: RoleOptions) => void
+  public readonly createRole: (...args: Parameters<roles.CreateRole>) => void
 
-  public readonly dropRole: (roleName: Name, options?: IfExistsOption) => void
+  public readonly dropRole: (...args: Parameters<roles.DropRole>) => void
 
-  public readonly alterRole: (roleName: Name, roleOptions: RoleOptions) => void
+  public readonly alterRole: (...args: Parameters<roles.AlterRole>) => void
 
-  public readonly renameRole: (oldRoleName: Name, newRoleName: Name) => void
+  public readonly renameRole: (...args: Parameters<roles.RenameRole>) => void
 
-  public readonly createFunction: (
-    functionName: Name,
-    functionParams: FunctionParam[],
-    functionOptions: FunctionOptions,
-    definition: Value,
-  ) => void
+  public readonly createFunction: (...args: Parameters<functions.CreateFunction>) => void
 
-  public readonly dropFunction: (functionName: Name, functionParams: FunctionParam[], dropOptions?: DropOptions) => void
+  public readonly dropFunction: (...args: Parameters<functions.DropFunction>) => void
 
-  public readonly renameFunction: (
-    oldFunctionName: Name,
-    functionParams: FunctionParam[],
-    newFunctionName: Name,
-  ) => void
+  public readonly renameFunction: (...args: Parameters<functions.RenameFunction>) => void
 
-  public readonly createTrigger:
-    | ((tableName: Name, triggerName: Name, triggerOptions: TriggerOptions) => void)
-    | ((
-        tableName: Name,
-        triggerName: Name,
-        triggerOptions: TriggerOptions & FunctionOptions,
-        definition: Value,
-      ) => void)
+  public readonly createTrigger: (...args: Parameters<triggers.CreateTrigger>) => void
 
-  public readonly dropTrigger: (tableName: Name, triggerName: Name, dropOptions?: DropOptions) => void
+  public readonly dropTrigger: (...args: Parameters<triggers.DropTrigger>) => void
 
-  public readonly renameTrigger: (tableName: Name, oldTriggerName: Name, newTriggerName: Name) => void
+  public readonly renameTrigger: (...args: Parameters<triggers.RenameTrigger>) => void
 
-  public readonly createSchema: (schemaName: string, schemaOptions?: CreateSchemaOptions) => void
+  public readonly createSchema: (...args: Parameters<schemas.CreateSchema>) => void
 
-  public readonly dropSchema: (schemaName: string, dropOptions?: DropOptions) => void
+  public readonly dropSchema: (...args: Parameters<schemas.DropSchema>) => void
 
-  public readonly renameSchema: (oldSchemaName: string, newSchemaName: string) => void
+  public readonly renameSchema: (...args: Parameters<schemas.RenameSchema>) => void
 
-  public readonly createDomain: (domainName: Name, type: Type, domainOptions?: DomainOptionsCreate) => void
+  public readonly createDomain: (...args: Parameters<domains.CreateDomain>) => void
 
-  public readonly dropDomain: (domainName: Name, dropOptions?: DropOptions) => void
+  public readonly dropDomain: (...args: Parameters<domains.DropDomain>) => void
 
-  public readonly alterDomain: (domainName: Name, domainOptions: DomainOptionsAlter) => void
+  public readonly alterDomain: (...args: Parameters<domains.AlterDomain>) => void
 
-  public readonly renameDomain: (oldDomainName: Name, newDomainName: Name) => void
+  public readonly renameDomain: (...args: Parameters<domains.RenameDomain>) => void
 
-  public readonly createSequence: (sequenceName: Name, sequenceOptions?: SequenceOptionsCreate) => void
+  public readonly createSequence: (...args: Parameters<sequences.CreateSequence>) => void
 
-  public readonly dropSequence: (sequenceName: Name, dropOptions?: DropOptions) => void
+  public readonly dropSequence: (...args: Parameters<sequences.DropSequence>) => void
 
-  public readonly alterSequence: (sequenceName: Name, sequenceOptions: SequenceOptionsAlter) => void
+  public readonly alterSequence: (...args: Parameters<sequences.AlterSequence>) => void
 
-  public readonly renameSequence: (oldSequenceName: Name, newSequenceName: Name) => void
+  public readonly renameSequence: (...args: Parameters<sequences.RenameSequence>) => void
 
-  public readonly createOperator: (operatorName: Name, options?: CreateOperatorOptions) => void
+  public readonly createOperator: (...args: Parameters<operators.CreateOperator>) => void
 
-  public readonly dropOperator: (operatorName: Name, dropOptions?: DropOperatorOptions) => void
+  public readonly dropOperator: (...args: Parameters<operators.DropOperator>) => void
 
-  public readonly createOperatorClass: (
-    operatorClassName: Name,
-    type: Type,
-    indexMethod: string,
-    operatorList: OperatorListDefinition[],
-    options: CreateOperatorClassOptions,
-  ) => void
+  public readonly createOperatorClass: (...args: Parameters<operators.CreateOperatorClass>) => void
 
-  public readonly dropOperatorClass: (operatorClassName: Name, indexMethod: string, dropOptions?: DropOptions) => void
+  public readonly dropOperatorClass: (...args: Parameters<operators.DropOperatorClass>) => void
 
-  public readonly renameOperatorClass: (
-    oldOperatorClassName: Name,
-    indexMethod: string,
-    newOperatorClassName: Name,
-  ) => void
+  public readonly renameOperatorClass: (...args: Parameters<operators.RenameOperatorClass>) => void
 
-  public readonly createOperatorFamily: (operatorFamilyName: Name, indexMethod: string) => void
+  public readonly createOperatorFamily: (...args: Parameters<operators.CreateOperatorFamily>) => void
 
-  public readonly dropOperatorFamily: (operatorFamilyName: Name, newSchemaName: Name, dropOptions?: DropOptions) => void
+  public readonly dropOperatorFamily: (...args: Parameters<operators.DropOperatorFamily>) => void
 
-  public readonly renameOperatorFamily: (
-    oldOperatorFamilyName: Name,
-    indexMethod: string,
-    newOperatorFamilyName: Name,
-  ) => void
+  public readonly renameOperatorFamily: (...args: Parameters<operators.RenameOperatorFamily>) => void
 
-  public readonly addToOperatorFamily: (
-    operatorFamilyName: Name,
-    indexMethod: string,
-    operatorList: OperatorListDefinition[],
-  ) => void
+  public readonly addToOperatorFamily: (...args: Parameters<operators.AddToOperatorFamily>) => void
 
-  public readonly removeFromOperatorFamily: (
-    operatorFamilyName: Name,
-    indexMethod: string,
-    operatorList: OperatorListDefinition[],
-  ) => void
+  public readonly removeFromOperatorFamily: (...args: Parameters<operators.RemoveFromOperatorFamily>) => void
 
-  public readonly createPolicy: (tableName: Name, policyName: string, options?: CreatePolicyOptions) => void
+  public readonly createPolicy: (...args: Parameters<policies.CreatePolicy>) => void
 
-  public readonly dropPolicy: (tableName: Name, policyName: string, options?: IfExistsOption) => void
+  public readonly dropPolicy: (...args: Parameters<policies.DropPolicy>) => void
 
-  public readonly alterPolicy: (tableName: Name, policyName: string, options: PolicyOptions) => void
+  public readonly alterPolicy: (...args: Parameters<policies.AlterPolicy>) => void
 
-  public readonly renamePolicy: (tableName: Name, policyName: string, newPolicyName: string) => void
+  public readonly renamePolicy: (...args: Parameters<policies.RenamePolicy>) => void
 
-  public readonly createView: (viewName: Name, options: CreateViewOptions, definition: string) => void
+  public readonly createView: (...args: Parameters<views.CreateView>) => void
 
-  public readonly dropView: (viewName: Name, options?: DropOptions) => void
+  public readonly dropView: (...args: Parameters<views.DropView>) => void
 
-  public readonly alterView: (viewName: Name, options: AlterViewOptions) => void
+  public readonly alterView: (...args: Parameters<views.AlterView>) => void
 
-  public readonly alterViewColumn: (viewName: Name, columnName: string, options: AlterViewColumnOptions) => void
+  public readonly alterViewColumn: (...args: Parameters<views.AlterViewColumn>) => void
 
-  public readonly renameView: (viewName: Name, newViewName: Name) => void
+  public readonly renameView: (...args: Parameters<views.RenameView>) => void
 
-  public readonly createMaterializedView: (
-    viewName: Name,
-    options: mViews.CreateMaterializedViewOptions,
-    definition: string,
-  ) => void
+  public readonly createMaterializedView: (...args: Parameters<mViews.CreateMaterializedView>) => void
 
-  public readonly dropMaterializedView: (viewName: Name, options?: DropOptions) => void
+  public readonly dropMaterializedView: (...args: Parameters<mViews.DropMaterializedView>) => void
 
-  public readonly alterMaterializedView: (viewName: Name, options: mViews.AlterMaterializedViewOptions) => void
+  public readonly alterMaterializedView: (...args: Parameters<mViews.AlterMaterializedView>) => void
 
-  public readonly renameMaterializedView: (viewName: Name, newViewName: Name) => void
+  public readonly renameMaterializedView: (...args: Parameters<mViews.RenameMaterializedView>) => void
 
-  public readonly renameMaterializedViewColumn: (viewName: Name, columnName: string, newColumnName: string) => void
+  public readonly renameMaterializedViewColumn: (...args: Parameters<mViews.RenameMaterializedViewColumn>) => void
 
-  public readonly refreshMaterializedView: (viewName: Name, options?: mViews.RefreshMaterializedViewOptions) => void
+  public readonly refreshMaterializedView: (...args: Parameters<mViews.RefreshMaterializedView>) => void
 
-  public readonly sql: (sql: string, args?: object) => void
+  public readonly sql: (...args: Parameters<other.Sql>) => void
 
   public readonly func: (sql: string) => PgLiteral
 
-  public readonly db: Partial<DB>
+  public readonly db: DB
 
   private _steps: string[]
 
@@ -316,10 +203,8 @@ export default class MigrationBuilder {
     // by default, all migrations are wrapped in a transaction
     this._useTransaction = true
 
-    interface Operation {
-      (...args: any[]): string | string[]
-      reverse?: (...args: any[]) => string | string[]
-    }
+    type OperationFn = (...args: any[]) => string | string[]
+    type Operation = OperationFn & { reverse?: OperationFn }
 
     // this function wraps each operation within a function that either
     // calls the operation or its reverse, and appends the result (array of sql statements)
@@ -457,7 +342,7 @@ export default class MigrationBuilder {
     return this
   }
 
-  public noTransaction(): this {
+  noTransaction(): this {
     this._useTransaction = false
     return this
   }
diff --git a/src/migration.ts b/src/migration.ts
index 7523dc4..1cb511c 100644
--- a/src/migration.ts
+++ b/src/migration.ts
@@ -10,11 +10,11 @@ import fs from 'fs'
 import mkdirp from 'mkdirp'
 import path from 'path'
 import { promisify } from 'util'
-import { DB } from './db'
-import { ColumnDefinitions } from './definitions'
-import MigrationBuilder, { MigrationAction, MigrationBuilderActions } from './migration-builder'
-import { MigrationDirection, RunnerOption } from './runner'
+import { DBConnection } from './db'
+import MigrationBuilder from './migration-builder'
+import { MigrationAction, MigrationBuilderActions, MigrationDirection, RunnerOption } from './types'
 import { getMigrationTableSchema } from './utils'
+import { ColumnDefinitions } from './operations/tablesTypes'
 
 const readdir = promisify(fs.readdir) // eslint-disable-line security/detect-non-literal-fs-filename
 const lstat = promisify(fs.lstat) // eslint-disable-line security/detect-non-literal-fs-filename
@@ -71,7 +71,7 @@ export class Migration implements RunMigration {
     return newFile
   }
 
-  public readonly db: DB
+  public readonly db: DBConnection
 
   public readonly path: string
 
@@ -90,7 +90,7 @@ export class Migration implements RunMigration {
   public readonly log: typeof console.log
 
   constructor(
-    db: DB,
+    db: DBConnection,
     migrationPath: string,
     { up, down }: MigrationBuilderActions,
     options: RunnerOption,
diff --git a/src/operations/PgLiteral.ts b/src/operations/PgLiteral.ts
new file mode 100644
index 0000000..078ec5f
--- /dev/null
+++ b/src/operations/PgLiteral.ts
@@ -0,0 +1,17 @@
+// This is used to create unescaped strings
+// exposed in the migrations via pgm.func
+export default class PgLiteral {
+  static create(str: string): PgLiteral {
+    return new PgLiteral(str)
+  }
+
+  private readonly _str: string
+
+  constructor(str: string) {
+    this._str = str
+  }
+
+  toString(): string {
+    return this._str
+  }
+}
diff --git a/src/operations/domains.ts b/src/operations/domains.ts
index 129b514..6d2a0e0 100644
--- a/src/operations/domains.ts
+++ b/src/operations/domains.ts
@@ -1,28 +1,11 @@
-import { DropOptions, Name, Type, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { applyType, escapeValue } from '../utils'
+import { CreateDomain, DropDomain, AlterDomain, RenameDomain } from './domainsTypes'
 
-export interface DomainOptions {
-  default?: Value
-  notNull?: boolean
-  check?: string
-  constraintName?: string
-}
-
-export interface DomainOptionsCreateEn {
-  collation?: string
-}
-
-export type DomainOptionsCreate = DomainOptionsCreateEn & DomainOptions
-
-export interface DomainOptionsAlterEn {
-  allowNull?: boolean
-}
-
-export type DomainOptionsAlter = DomainOptionsAlterEn & DomainOptions
+export { CreateDomain, DropDomain, AlterDomain, RenameDomain }
 
 export function dropDomain(mOptions: MigrationOptions) {
-  const _drop = (domainName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropDomain = (domainName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const domainNameStr = mOptions.literal(domainName)
@@ -32,7 +15,7 @@ export function dropDomain(mOptions: MigrationOptions) {
 }
 
 export function createDomain(mOptions: MigrationOptions) {
-  const _create = (domainName: Name, type: Type, options: DomainOptionsCreate = {}) => {
+  const _create: CreateDomain = (domainName, type, options = {}) => {
     const { default: defaultValue, collation, notNull, check, constraintName } = options
     const constraints = []
     if (collation) {
@@ -61,12 +44,12 @@ export function createDomain(mOptions: MigrationOptions) {
 
     return `CREATE DOMAIN ${domainNameStr} AS ${typeStr}${constraintsStr};`
   }
-  _create.reverse = (domainName: Name, type: Type, options: DropOptions) => dropDomain(mOptions)(domainName, options)
+  _create.reverse = (domainName, type, options) => dropDomain(mOptions)(domainName, options)
   return _create
 }
 
 export function alterDomain(mOptions: MigrationOptions) {
-  const _alter = (domainName: Name, options: DomainOptionsAlter) => {
+  const _alter: AlterDomain = (domainName, options) => {
     const { default: defaultValue, notNull, allowNull, check, constraintName } = options
     const actions = []
     if (defaultValue === null) {
@@ -89,11 +72,11 @@ export function alterDomain(mOptions: MigrationOptions) {
 }
 
 export function renameDomain(mOptions: MigrationOptions) {
-  const _rename = (domainName: Name, newDomainName: Name) => {
+  const _rename: RenameDomain = (domainName, newDomainName) => {
     const domainNameStr = mOptions.literal(domainName)
     const newDomainNameStr = mOptions.literal(newDomainName)
     return `ALTER DOMAIN ${domainNameStr} RENAME TO ${newDomainNameStr};`
   }
-  _rename.reverse = (domainName: Name, newDomainName: Name) => _rename(newDomainName, domainName)
+  _rename.reverse = (domainName, newDomainName) => _rename(newDomainName, domainName)
   return _rename
 }
diff --git a/src/operations/domainsTypes.ts b/src/operations/domainsTypes.ts
new file mode 100644
index 0000000..b4f9e7c
--- /dev/null
+++ b/src/operations/domainsTypes.ts
@@ -0,0 +1,27 @@
+import { Value, Name, Type, DropOptions } from './generalTypes'
+
+export interface DomainOptions {
+  default?: Value
+  notNull?: boolean
+  check?: string
+  constraintName?: string
+}
+
+export interface DomainOptionsCreate extends DomainOptions {
+  collation?: string
+}
+
+export interface DomainOptionsAlter extends DomainOptions {
+  allowNull?: boolean
+}
+
+type CreateDomainFn = (
+  domainName: Name,
+  type: Type,
+  domainOptions?: DomainOptionsCreate & DropOptions,
+) => string | string[]
+export type CreateDomain = CreateDomainFn & { reverse: CreateDomainFn }
+export type DropDomain = (domainName: Name, dropOptions?: DropOptions) => string | string[]
+export type AlterDomain = (domainName: Name, domainOptions: DomainOptionsAlter) => string | string[]
+type RenameDomainFn = (oldDomainName: Name, newDomainName: Name) => string | string[]
+export type RenameDomain = RenameDomainFn & { reverse: RenameDomainFn }
diff --git a/src/operations/extensions.ts b/src/operations/extensions.ts
index 54a0818..3478a20 100644
--- a/src/operations/extensions.ts
+++ b/src/operations/extensions.ts
@@ -1,64 +1,11 @@
 import _ from 'lodash'
-import { DropOptions, LiteralUnion } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
+import { CreateExtension, DropExtension } from './extensionsTypes'
 
-export type Extension =
-  | 'adminpack'
-  | 'amcheck'
-  | 'auth_delay'
-  | 'auto_explain'
-  | 'bloom'
-  | 'btree_gin'
-  | 'btree_gist'
-  | 'citext'
-  | 'cube'
-  | 'dblink'
-  | 'dict_int'
-  | 'dict_xsyn'
-  | 'earthdistance'
-  | 'file_fdw'
-  | 'fuzzystrmatch'
-  | 'hstore'
-  | 'intagg'
-  | 'intarray'
-  | 'isn'
-  | 'lo'
-  | 'ltree'
-  | 'pageinspect'
-  | 'passwordcheck'
-  | 'pg_buffercache'
-  | 'pgcrypto'
-  | 'pg_freespacemap'
-  | 'pg_prewarm'
-  | 'pgrowlocks'
-  | 'pg_stat_statements'
-  | 'pgstattuple'
-  | 'pg_trgm'
-  | 'pg_visibility'
-  | 'postgres_fdw'
-  | 'seg'
-  | 'sepgsql'
-  | 'spi'
-  | 'sslinfo'
-  | 'tablefunc'
-  | 'tcn'
-  | 'test_decoding'
-  | 'tsm_system_rows'
-  | 'tsm_system_time'
-  | 'unaccent'
-  | 'uuid-ossp'
-  | 'xml2'
-
-export interface CreateExtensionOptions {
-  ifNotExists?: boolean
-  schema?: string
-}
+export { CreateExtension, DropExtension }
 
 export function dropExtension(mOptions: MigrationOptions) {
-  const _drop = (
-    extensions: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
-    { ifExists, cascade }: DropOptions = {},
-  ) => {
+  const _drop: DropExtension = (extensions, { ifExists, cascade } = {}) => {
     if (!_.isArray(extensions)) extensions = [extensions] // eslint-disable-line no-param-reassign
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
@@ -71,10 +18,7 @@ export function dropExtension(mOptions: MigrationOptions) {
 }
 
 export function createExtension(mOptions: MigrationOptions) {
-  const _create = (
-    extensions: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
-    { ifNotExists, schema }: CreateExtensionOptions = {},
-  ) => {
+  const _create: CreateExtension = (extensions, { ifNotExists, schema } = {}) => {
     if (!_.isArray(extensions)) extensions = [extensions] // eslint-disable-line no-param-reassign
     const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : ''
     const schemaStr = schema ? ` SCHEMA ${mOptions.literal(schema)}` : ''
diff --git a/src/operations/extensionsTypes.ts b/src/operations/extensionsTypes.ts
new file mode 100644
index 0000000..5f7c07d
--- /dev/null
+++ b/src/operations/extensionsTypes.ts
@@ -0,0 +1,62 @@
+import { LiteralUnion, DropOptions, IfNotExistsOption } from './generalTypes'
+
+export type Extension =
+  | 'adminpack'
+  | 'amcheck'
+  | 'auth_delay'
+  | 'auto_explain'
+  | 'bloom'
+  | 'btree_gin'
+  | 'btree_gist'
+  | 'citext'
+  | 'cube'
+  | 'dblink'
+  | 'dict_int'
+  | 'dict_xsyn'
+  | 'earthdistance'
+  | 'file_fdw'
+  | 'fuzzystrmatch'
+  | 'hstore'
+  | 'intagg'
+  | 'intarray'
+  | 'isn'
+  | 'lo'
+  | 'ltree'
+  | 'pageinspect'
+  | 'passwordcheck'
+  | 'pg_buffercache'
+  | 'pgcrypto'
+  | 'pg_freespacemap'
+  | 'pg_prewarm'
+  | 'pgrowlocks'
+  | 'pg_stat_statements'
+  | 'pgstattuple'
+  | 'pg_trgm'
+  | 'pg_visibility'
+  | 'postgres_fdw'
+  | 'seg'
+  | 'sepgsql'
+  | 'spi'
+  | 'sslinfo'
+  | 'tablefunc'
+  | 'tcn'
+  | 'test_decoding'
+  | 'tsm_system_rows'
+  | 'tsm_system_time'
+  | 'unaccent'
+  | 'uuid-ossp'
+  | 'xml2'
+
+export interface CreateExtensionOptions extends IfNotExistsOption {
+  schema?: string
+}
+
+type CreateExtensionFn = (
+  extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
+  options?: CreateExtensionOptions & DropOptions,
+) => string | string[]
+export type CreateExtension = CreateExtensionFn & { reverse: CreateExtensionFn }
+export type DropExtension = (
+  extension: LiteralUnion<Extension> | Array<LiteralUnion<Extension>>,
+  dropOptions?: DropOptions,
+) => string | string[]
diff --git a/src/operations/functions.ts b/src/operations/functions.ts
index 37a5aad..e361d89 100644
--- a/src/operations/functions.ts
+++ b/src/operations/functions.ts
@@ -1,28 +1,11 @@
-import { DropOptions, Name, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { escapeValue, formatParams } from '../utils'
+import { CreateFunction, DropFunction, RenameFunction } from './functionsTypes'
 
-export interface FunctionParamType {
-  mode?: 'IN' | 'OUT' | 'INOUT' | 'VARIADIC'
-  name?: string
-  type: string
-  default?: Value
-}
-
-export type FunctionParam = string | FunctionParamType
-
-export interface FunctionOptions {
-  returns?: string
-  language: string
-  replace?: boolean
-  window?: boolean
-  behavior?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
-  onNull?: boolean
-  parallel?: 'UNSAFE' | 'RESTRICTED' | 'SAFE'
-}
+export { CreateFunction, DropFunction, RenameFunction }
 
 export function dropFunction(mOptions: MigrationOptions) {
-  const _drop = (functionName: Name, functionParams: FunctionParam[] = [], { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropFunction = (functionName, functionParams = [], { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const paramsStr = formatParams(functionParams, mOptions)
@@ -33,12 +16,7 @@ export function dropFunction(mOptions: MigrationOptions) {
 }
 
 export function createFunction(mOptions: MigrationOptions) {
-  const _create = (
-    functionName: Name,
-    functionParams: FunctionParam[] = [],
-    functionOptions: Partial<FunctionOptions> = {},
-    definition: Value,
-  ) => {
+  const _create: CreateFunction = (functionName, functionParams = [], functionOptions, definition) => {
     const { replace, returns = 'void', language, window, behavior = 'VOLATILE', onNull, parallel } = functionOptions
     const options = []
     if (behavior) {
@@ -73,13 +51,13 @@ export function createFunction(mOptions: MigrationOptions) {
 }
 
 export function renameFunction(mOptions: MigrationOptions) {
-  const _rename = (oldFunctionName: Name, functionParams: FunctionParam[] = [], newFunctionName: Name) => {
+  const _rename: RenameFunction = (oldFunctionName, functionParams = [], newFunctionName) => {
     const paramsStr = formatParams(functionParams, mOptions)
     const oldFunctionNameStr = mOptions.literal(oldFunctionName)
     const newFunctionNameStr = mOptions.literal(newFunctionName)
     return `ALTER FUNCTION ${oldFunctionNameStr}${paramsStr} RENAME TO ${newFunctionNameStr};`
   }
-  _rename.reverse = (oldFunctionName: Name, functionParams: FunctionParam[], newFunctionName: Name) =>
+  _rename.reverse = (oldFunctionName, functionParams, newFunctionName) =>
     _rename(newFunctionName, functionParams, oldFunctionName)
   return _rename
 }
diff --git a/src/operations/functionsTypes.ts b/src/operations/functionsTypes.ts
new file mode 100644
index 0000000..3113f0e
--- /dev/null
+++ b/src/operations/functionsTypes.ts
@@ -0,0 +1,39 @@
+import { Name, Value, DropOptions } from './generalTypes'
+
+export interface FunctionParamType {
+  mode?: 'IN' | 'OUT' | 'INOUT' | 'VARIADIC'
+  name?: string
+  type: string
+  default?: Value
+}
+
+export type FunctionParam = string | FunctionParamType
+
+export interface FunctionOptions {
+  returns?: string
+  language: string
+  replace?: boolean
+  window?: boolean
+  behavior?: 'IMMUTABLE' | 'STABLE' | 'VOLATILE'
+  onNull?: boolean
+  parallel?: 'UNSAFE' | 'RESTRICTED' | 'SAFE'
+}
+
+type CreateFunctionFn = (
+  functionName: Name,
+  functionParams: FunctionParam[],
+  functionOptions: FunctionOptions & DropOptions,
+  definition: Value,
+) => string | string[]
+export type CreateFunction = CreateFunctionFn & { reverse: CreateFunctionFn }
+export type DropFunction = (
+  functionName: Name,
+  functionParams: FunctionParam[],
+  dropOptions?: DropOptions,
+) => string | string[]
+type RenameFunctionFn = (
+  oldFunctionName: Name,
+  functionParams: FunctionParam[],
+  newFunctionName: Name,
+) => string | string[]
+export type RenameFunction = RenameFunctionFn & { reverse: RenameFunctionFn }
diff --git a/src/operations/generalTypes.ts b/src/operations/generalTypes.ts
new file mode 100644
index 0000000..8b3cd3a
--- /dev/null
+++ b/src/operations/generalTypes.ts
@@ -0,0 +1,23 @@
+import PgLiteral from './PgLiteral'
+
+export type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never })
+
+export type Value = null | boolean | string | number | PgLiteral | Value[]
+
+export type Type = string | { type: string }
+
+export type Name = string | { schema?: string; name: string }
+
+export interface IfNotExistsOption {
+  ifNotExists?: boolean
+}
+
+export interface IfExistsOption {
+  ifExists?: boolean
+}
+
+export interface CascadeOption {
+  cascade?: boolean
+}
+
+export type DropOptions = IfExistsOption & CascadeOption
diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts
index 22d8534..c3a413e 100644
--- a/src/operations/indexes.ts
+++ b/src/operations/indexes.ts
@@ -1,22 +1,9 @@
 import _ from 'lodash'
-import { DropOptions, Name } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions, Literal } from '../types'
+import { Name } from './generalTypes'
+import { DropIndex, CreateIndex, CreateIndexOptions, DropIndexOptions } from './indexesTypes'
 
-export interface CreateIndexOptions {
-  name?: string
-  unique?: boolean
-  where?: string
-  concurrently?: boolean
-  opclass?: string
-  method?: 'btree' | 'hash' | 'gist' | 'spgist' | 'gin'
-}
-
-export interface DropIndexOptionsEn {
-  name?: string
-  concurrently?: boolean
-}
-
-export type DropIndexOptions = DropIndexOptionsEn & DropOptions
+export { CreateIndex, DropIndex }
 
 function generateIndexName(table: Name, columns: string | string[], options: CreateIndexOptions | DropIndexOptions) {
   if (options.name) {
@@ -32,7 +19,7 @@ function generateIndexName(table: Name, columns: string | string[], options: Cre
     : `${table}_${cols}${uniq}_index`
 }
 
-function generateColumnString(column: string, literal: (v: Name) => string) {
+function generateColumnString(column: string, literal: Literal) {
   const openingBracketPos = column.indexOf('(')
   const closingBracketPos = column.indexOf(')')
   const isFunction = openingBracketPos >= 0 && closingBracketPos > openingBracketPos
@@ -41,14 +28,14 @@ function generateColumnString(column: string, literal: (v: Name) => string) {
     : literal(column) // single column
 }
 
-function generateColumnsString(columns: string | string[], literal: (v: Name) => string) {
+function generateColumnsString(columns: string | string[], literal: Literal) {
   return _.isArray(columns)
     ? columns.map(column => generateColumnString(column, literal)).join(', ')
     : generateColumnString(columns, literal)
 }
 
 export function dropIndex(mOptions: MigrationOptions) {
-  const _drop = (tableName: Name, columns: string | string[], options: DropIndexOptions = {}) => {
+  const _drop: DropIndex = (tableName, columns, options = {}) => {
     const { concurrently, ifExists, cascade } = options
     const concurrentlyStr = concurrently ? ' CONCURRENTLY' : ''
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
@@ -62,7 +49,7 @@ export function dropIndex(mOptions: MigrationOptions) {
 }
 
 export function createIndex(mOptions: MigrationOptions) {
-  const _create = (tableName: Name, columns: string | string[], options: CreateIndexOptions = {}) => {
+  const _create: CreateIndex = (tableName, columns, options = {}) => {
     /*
     columns - the column, columns, or expression to create the index on
 
diff --git a/src/operations/indexesTypes.ts b/src/operations/indexesTypes.ts
new file mode 100644
index 0000000..bc423f1
--- /dev/null
+++ b/src/operations/indexesTypes.ts
@@ -0,0 +1,24 @@
+import { Name, DropOptions } from './generalTypes'
+
+export interface CreateIndexOptions {
+  name?: string
+  unique?: boolean
+  where?: string
+  concurrently?: boolean
+  opclass?: string
+  method?: 'btree' | 'hash' | 'gist' | 'spgist' | 'gin'
+}
+
+export interface DropIndexOptions extends DropOptions {
+  name?: string
+  concurrently?: boolean
+}
+
+type CreateIndexFn = (
+  tableName: Name,
+  columns: string | string[],
+  options?: CreateIndexOptions & DropIndexOptions,
+) => string | string[]
+export type CreateIndex = CreateIndexFn & { reverse: CreateIndexFn }
+export type AddIndex = (tableName: Name, columns: string | string[], options?: CreateIndexOptions) => string | string[]
+export type DropIndex = (tableName: Name, columns: string | string[], options?: DropIndexOptions) => string | string[]
diff --git a/src/operations/operators.ts b/src/operations/operators.ts
index 253e4a2..90b0dd0 100644
--- a/src/operations/operators.ts
+++ b/src/operations/operators.ts
@@ -1,41 +1,34 @@
-import { Name, DropOptions, Type } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { applyType, formatParams } from '../utils'
-import { FunctionParam } from './functions'
-
-export interface CreateOperatorOptions {
-  procedure: Name
-  left?: Name
-  right?: Name
-  commutator?: Name
-  negator?: Name
-  restrict?: Name
-  join?: Name
-  hashes?: boolean
-  merges?: boolean
-}
-
-export interface DropOperatorOptions {
-  left?: Name
-  right?: Name
-  ifExists?: boolean
-  cascade?: boolean
-}
-
-export interface CreateOperatorClassOptions {
-  default?: boolean
-  family?: string
-}
-
-export interface OperatorListDefinition {
-  type: 'function' | 'operator'
-  number: number
-  name: Name
-  params?: FunctionParam[]
+import {
+  OperatorListDefinition,
+  CreateOperator,
+  DropOperator,
+  CreateOperatorClass,
+  DropOperatorClass,
+  RenameOperatorClass,
+  CreateOperatorFamily,
+  DropOperatorFamily,
+  AddToOperatorFamily,
+  RenameOperatorFamily,
+  RemoveFromOperatorFamily,
+} from './operatorsTypes'
+
+export {
+  CreateOperator,
+  DropOperator,
+  CreateOperatorClass,
+  DropOperatorClass,
+  RenameOperatorClass,
+  CreateOperatorFamily,
+  DropOperatorFamily,
+  AddToOperatorFamily,
+  RenameOperatorFamily,
+  RemoveFromOperatorFamily,
 }
 
 export function dropOperator(mOptions: MigrationOptions) {
-  const _drop = (operatorName: Name, options: DropOperatorOptions = {}) => {
+  const _drop: DropOperator = (operatorName, options = {}) => {
     const { ifExists, cascade, left, right } = options
 
     const operatorNameStr = mOptions.schemalize(operatorName)
@@ -51,7 +44,7 @@ export function dropOperator(mOptions: MigrationOptions) {
 }
 
 export function createOperator(mOptions: MigrationOptions) {
-  const _create = (operatorName: Name, options: Partial<CreateOperatorOptions> = {}) => {
+  const _create: CreateOperator = (operatorName, options) => {
     const { procedure, left, right, commutator, negator, restrict, join, hashes, merges } = options
 
     const defs = []
@@ -88,7 +81,7 @@ export function createOperator(mOptions: MigrationOptions) {
 }
 
 export function dropOperatorFamily(mOptions: MigrationOptions) {
-  const _drop = (operatorFamilyName: Name, indexMethod: string, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropOperatorFamily = (operatorFamilyName, indexMethod, { ifExists, cascade } = {}) => {
     const operatorFamilyNameStr = mOptions.literal(operatorFamilyName)
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
@@ -98,7 +91,7 @@ export function dropOperatorFamily(mOptions: MigrationOptions) {
 }
 
 export function createOperatorFamily(mOptions: MigrationOptions) {
-  const _create = (operatorFamilyName: Name, indexMethod: string) => {
+  const _create: CreateOperatorFamily = (operatorFamilyName, indexMethod) => {
     const operatorFamilyNameStr = mOptions.literal(operatorFamilyName)
     return `CREATE OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod};`
   }
@@ -125,39 +118,42 @@ const operatorMap = (mOptions: MigrationOptions) => ({ type, number, name, param
   throw new Error('Operator "type" must be either "function" or "operator"')
 }
 
-const changeOperatorFamily = (op: 'ADD' | 'DROP', reverse?: (mOptions: MigrationOptions) => any) => (
-  mOptions: MigrationOptions,
-) => {
-  const method = (operatorFamilyName: Name, indexMethod: string, operatorList: OperatorListDefinition[]) => {
+export const removeFromOperatorFamily = (mOptions: MigrationOptions) => {
+  const method: RemoveFromOperatorFamily = (operatorFamilyName, indexMethod, operatorList) => {
     const operatorFamilyNameStr = mOptions.literal(operatorFamilyName)
     const operatorListStr = operatorList.map(operatorMap(mOptions)).join(',\n  ')
 
-    return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ${op}
+    return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} DROP
   ${operatorListStr};`
   }
-  if (reverse) {
-    method.reverse = reverse(mOptions)
-  }
   return method
 }
+export const addToOperatorFamily = (mOptions: MigrationOptions) => {
+  const method: AddToOperatorFamily = (operatorFamilyName, indexMethod, operatorList) => {
+    const operatorFamilyNameStr = mOptions.literal(operatorFamilyName)
+    const operatorListStr = operatorList.map(operatorMap(mOptions)).join(',\n  ')
 
-export const removeFromOperatorFamily = changeOperatorFamily('DROP')
-export const addToOperatorFamily = changeOperatorFamily('ADD', removeFromOperatorFamily)
+    return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ADD
+  ${operatorListStr};`
+  }
+  method.reverse = removeFromOperatorFamily(mOptions)
+  return method
+}
 
 export function renameOperatorFamily(mOptions: MigrationOptions) {
-  const _rename = (oldOperatorFamilyName: Name, indexMethod: string, newOperatorFamilyName: Name) => {
+  const _rename: RenameOperatorFamily = (oldOperatorFamilyName, indexMethod, newOperatorFamilyName) => {
     const oldOperatorFamilyNameStr = mOptions.literal(oldOperatorFamilyName)
     const newOperatorFamilyNameStr = mOptions.literal(newOperatorFamilyName)
 
     return `ALTER OPERATOR FAMILY ${oldOperatorFamilyNameStr} USING ${indexMethod} RENAME TO ${newOperatorFamilyNameStr};`
   }
-  _rename.reverse = (oldOperatorFamilyName: Name, indexMethod: string, newOperatorFamilyName: Name) =>
+  _rename.reverse = (oldOperatorFamilyName, indexMethod, newOperatorFamilyName) =>
     _rename(newOperatorFamilyName, indexMethod, oldOperatorFamilyName)
   return _rename
 }
 
 export function dropOperatorClass(mOptions: MigrationOptions) {
-  const _drop = (operatorClassName: Name, indexMethod: string, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropOperatorClass = (operatorClassName, indexMethod, { ifExists, cascade } = {}) => {
     const operatorClassNameStr = mOptions.literal(operatorClassName)
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
@@ -168,13 +164,7 @@ export function dropOperatorClass(mOptions: MigrationOptions) {
 }
 
 export function createOperatorClass(mOptions: MigrationOptions) {
-  const _create = (
-    operatorClassName: Name,
-    type: Type,
-    indexMethod: string,
-    operatorList: OperatorListDefinition[],
-    options: CreateOperatorClassOptions,
-  ) => {
+  const _create: CreateOperatorClass = (operatorClassName, type, indexMethod, operatorList, options) => {
     const { default: isDefault, family } = options
     const operatorClassNameStr = mOptions.literal(operatorClassName)
     const defaultStr = isDefault ? ' DEFAULT' : ''
@@ -186,24 +176,19 @@ export function createOperatorClass(mOptions: MigrationOptions) {
     return `CREATE OPERATOR CLASS ${operatorClassNameStr}${defaultStr} FOR TYPE ${typeStr} USING ${indexMethodStr} ${familyStr} AS
   ${operatorListStr};`
   }
-  _create.reverse = (
-    operatorClassName: Name,
-    type: Type,
-    indexMethod: string,
-    operatorList: OperatorListDefinition[],
-    options: DropOptions,
-  ) => dropOperatorClass(mOptions)(operatorClassName, indexMethod, options)
+  _create.reverse = (operatorClassName, type, indexMethod, operatorList, options) =>
+    dropOperatorClass(mOptions)(operatorClassName, indexMethod, options)
   return _create
 }
 
 export function renameOperatorClass(mOptions: MigrationOptions) {
-  const _rename = (oldOperatorClassName: Name, indexMethod: string, newOperatorClassName: Name) => {
+  const _rename: RenameOperatorClass = (oldOperatorClassName, indexMethod, newOperatorClassName) => {
     const oldOperatorClassNameStr = mOptions.literal(oldOperatorClassName)
     const newOperatorClassNameStr = mOptions.literal(newOperatorClassName)
 
     return `ALTER OPERATOR CLASS ${oldOperatorClassNameStr} USING ${indexMethod} RENAME TO ${newOperatorClassNameStr};`
   }
-  _rename.reverse = (oldOperatorClassName: Name, indexMethod: string, newOperatorClassName: Name) =>
+  _rename.reverse = (oldOperatorClassName, indexMethod, newOperatorClassName) =>
     _rename(newOperatorClassName, indexMethod, oldOperatorClassName)
   return _rename
 }
diff --git a/src/operations/operatorsTypes.ts b/src/operations/operatorsTypes.ts
new file mode 100644
index 0000000..35bad84
--- /dev/null
+++ b/src/operations/operatorsTypes.ts
@@ -0,0 +1,78 @@
+import { Name, Type, DropOptions } from './generalTypes'
+import { FunctionParam } from './functionsTypes'
+
+export interface CreateOperatorOptions {
+  procedure: Name
+  left?: Name
+  right?: Name
+  commutator?: Name
+  negator?: Name
+  restrict?: Name
+  join?: Name
+  hashes?: boolean
+  merges?: boolean
+}
+
+export interface DropOperatorOptions extends DropOptions {
+  left?: Name
+  right?: Name
+}
+
+export interface CreateOperatorClassOptions {
+  default?: boolean
+  family?: string
+}
+
+export interface OperatorListDefinition {
+  type: 'function' | 'operator'
+  number: number
+  name: Name
+  params?: FunctionParam[]
+}
+
+type CreateOperatorFn = (operatorName: Name, options?: CreateOperatorOptions & DropOperatorOptions) => string | string[]
+export type CreateOperator = CreateOperatorFn & { reverse: CreateOperatorFn }
+export type DropOperator = (operatorName: Name, dropOptions?: DropOperatorOptions) => string | string[]
+type CreateOperatorClassFn = (
+  operatorClassName: Name,
+  type: Type,
+  indexMethod: Name,
+  operatorList: OperatorListDefinition[],
+  options: CreateOperatorClassOptions & DropOptions,
+) => string | string[]
+export type CreateOperatorClass = CreateOperatorClassFn & { reverse: CreateOperatorClassFn }
+export type DropOperatorClass = (
+  operatorClassName: Name,
+  indexMethod: Name,
+  dropOptions?: DropOptions,
+) => string | string[]
+type RenameOperatorClassFn = (
+  oldOperatorClassName: Name,
+  indexMethod: Name,
+  newOperatorClassName: Name,
+) => string | string[]
+export type RenameOperatorClass = RenameOperatorClassFn & { reverse: RenameOperatorClassFn }
+type CreateOperatorFamilyFn = (operatorFamilyName: Name, indexMethod: Name, options?: DropOptions) => string | string[]
+export type CreateOperatorFamily = CreateOperatorFamilyFn & { reverse: CreateOperatorFamilyFn }
+export type DropOperatorFamily = (
+  operatorFamilyName: Name,
+  newSchemaName: Name,
+  dropOptions?: DropOptions,
+) => string | string[]
+type RenameOperatorFamilyFn = (
+  oldOperatorFamilyName: Name,
+  indexMethod: Name,
+  newOperatorFamilyName: Name,
+) => string | string[]
+export type RenameOperatorFamily = RenameOperatorFamilyFn & { reverse: RenameOperatorFamilyFn }
+type AddToOperatorFamilyFn = (
+  operatorFamilyName: Name,
+  indexMethod: Name,
+  operatorList: OperatorListDefinition[],
+) => string | string[]
+export type AddToOperatorFamily = AddToOperatorFamilyFn & { reverse: AddToOperatorFamilyFn }
+export type RemoveFromOperatorFamily = (
+  operatorFamilyName: Name,
+  indexMethod: Name,
+  operatorList: OperatorListDefinition[],
+) => string | string[]
diff --git a/src/operations/other.ts b/src/operations/other.ts
index f23baed..ff11045 100644
--- a/src/operations/other.ts
+++ b/src/operations/other.ts
@@ -1,11 +1,12 @@
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { createTransformer } from '../utils'
-import { Name } from '../definitions'
+import { Sql } from './othersTypes'
 
-// eslint-disable-next-line import/prefer-default-export
-export function sql(mOptions: MigrationOptions) {
+export { Sql }
+
+export function sql(mOptions: MigrationOptions): Sql {
   const t = createTransformer(mOptions.literal)
-  return (sqlStr: string, args?: { [key: string]: Name }) => {
+  return (sqlStr, args) => {
     // applies some very basic templating using the utils.p
     let s: string = t(sqlStr, args)
     // add trailing ; if not present
diff --git a/src/operations/othersTypes.ts b/src/operations/othersTypes.ts
new file mode 100644
index 0000000..2438909
--- /dev/null
+++ b/src/operations/othersTypes.ts
@@ -0,0 +1,3 @@
+import { Name } from './generalTypes'
+
+export type Sql = (sqlStr: string, args?: { [key: string]: Name }) => string | string[]
diff --git a/src/operations/policies.ts b/src/operations/policies.ts
index f04e658..bb3790f 100644
--- a/src/operations/policies.ts
+++ b/src/operations/policies.ts
@@ -1,19 +1,9 @@
-import { IfExistsOption, Name } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
+import { PolicyOptions, CreatePolicy, DropPolicy, AlterPolicy, RenamePolicy } from './policiesTypes'
 
-export interface PolicyOptions {
-  role: string | string[]
-  using: string
-  check: string
-}
-
-export interface CreatePolicyOptionsEn {
-  command: 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE'
-}
-
-export type CreatePolicyOptions = CreatePolicyOptionsEn & PolicyOptions
+export { CreatePolicy, DropPolicy, AlterPolicy, RenamePolicy }
 
-const makeClauses = ({ role, using, check }: Partial<PolicyOptions>) => {
+const makeClauses = ({ role, using, check }: PolicyOptions) => {
   const roles = (Array.isArray(role) ? role : [role]).join(', ')
   const clauses: string[] = []
   if (roles) {
@@ -29,7 +19,7 @@ const makeClauses = ({ role, using, check }: Partial<PolicyOptions>) => {
 }
 
 export function dropPolicy(mOptions: MigrationOptions) {
-  const _drop = (tableName: Name, policyName: string, { ifExists }: IfExistsOption = {}) => {
+  const _drop: DropPolicy = (tableName, policyName, { ifExists } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const policyNameStr = mOptions.literal(policyName)
     const tableNameStr = mOptions.literal(tableName)
@@ -39,8 +29,8 @@ export function dropPolicy(mOptions: MigrationOptions) {
 }
 
 export function createPolicy(mOptions: MigrationOptions) {
-  const _create = (tableName: Name, policyName: string, options: Partial<CreatePolicyOptions> = {}) => {
-    const createOptions: Partial<CreatePolicyOptions> = {
+  const _create: CreatePolicy = (tableName, policyName, options = {}) => {
+    const createOptions = {
       ...options,
       role: options.role || 'PUBLIC',
     }
@@ -55,7 +45,7 @@ export function createPolicy(mOptions: MigrationOptions) {
 }
 
 export function alterPolicy(mOptions: MigrationOptions) {
-  const _alter = (tableName: Name, policyName: string, options: Partial<PolicyOptions> = {}) => {
+  const _alter: AlterPolicy = (tableName, policyName, options = {}) => {
     const clausesStr = makeClauses(options).join(' ')
     const policyNameStr = mOptions.literal(policyName)
     const tableNameStr = mOptions.literal(tableName)
@@ -65,13 +55,12 @@ export function alterPolicy(mOptions: MigrationOptions) {
 }
 
 export function renamePolicy(mOptions: MigrationOptions) {
-  const _rename = (tableName: Name, policyName: string, newPolicyName: string) => {
+  const _rename: RenamePolicy = (tableName, policyName, newPolicyName) => {
     const policyNameStr = mOptions.literal(policyName)
     const newPolicyNameStr = mOptions.literal(newPolicyName)
     const tableNameStr = mOptions.literal(tableName)
     return `ALTER POLICY ${policyNameStr} ON ${tableNameStr} RENAME TO ${newPolicyNameStr};`
   }
-  _rename.reverse = (tableName: Name, policyName: string, newPolicyName: string) =>
-    _rename(tableName, newPolicyName, policyName)
+  _rename.reverse = (tableName, policyName, newPolicyName) => _rename(tableName, newPolicyName, policyName)
   return _rename
 }
diff --git a/src/operations/policiesTypes.ts b/src/operations/policiesTypes.ts
new file mode 100644
index 0000000..b4005a3
--- /dev/null
+++ b/src/operations/policiesTypes.ts
@@ -0,0 +1,24 @@
+import { Name, IfExistsOption } from './generalTypes'
+
+export interface PolicyOptions {
+  role?: string | string[]
+  using?: string
+  check?: string
+}
+
+interface CreatePolicyOptionsEn {
+  command?: 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE'
+}
+
+export type CreatePolicyOptions = CreatePolicyOptionsEn & PolicyOptions
+
+type CreatePolicyFn = (
+  tableName: Name,
+  policyName: string,
+  options?: CreatePolicyOptions & IfExistsOption,
+) => string | string[]
+export type CreatePolicy = CreatePolicyFn & { reverse: CreatePolicyFn }
+export type DropPolicy = (tableName: Name, policyName: string, options?: IfExistsOption) => string | string[]
+export type AlterPolicy = (tableName: Name, policyName: string, options: PolicyOptions) => string | string[]
+type RenamePolicyFn = (tableName: Name, policyName: string, newPolicyName: string) => string | string[]
+export type RenamePolicy = RenamePolicyFn & { reverse: RenamePolicyFn }
diff --git a/src/operations/roles.ts b/src/operations/roles.ts
index 6bcdae7..bfede10 100644
--- a/src/operations/roles.ts
+++ b/src/operations/roles.ts
@@ -1,24 +1,9 @@
 import { isArray } from 'lodash'
-import { IfExistsOption, Name, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { escapeValue } from '../utils'
+import { CreateRole, DropRole, AlterRole, RenameRole, RoleOptions } from './rolesTypes'
 
-export interface RoleOptions {
-  superuser?: boolean
-  createdb?: boolean
-  createrole?: boolean
-  inherit?: boolean
-  login?: boolean
-  replication?: boolean
-  bypassrls?: boolean
-  limit?: number
-  password?: Value
-  encrypted?: boolean
-  valid?: Value
-  inRole?: string | string[]
-  role?: string | string[]
-  admin?: string | string[]
-}
+export { CreateRole, DropRole, AlterRole, RenameRole }
 
 const formatRoleOptions = (roleOptions: RoleOptions = {}) => {
   const options = []
@@ -71,7 +56,7 @@ const formatRoleOptions = (roleOptions: RoleOptions = {}) => {
 }
 
 export function dropRole(mOptions: MigrationOptions) {
-  const _drop = (roleName: Name, { ifExists }: IfExistsOption = {}) => {
+  const _drop: DropRole = (roleName, { ifExists } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const roleNameStr = mOptions.literal(roleName)
     return `DROP ROLE${ifExistsStr} ${roleNameStr};`
@@ -80,7 +65,7 @@ export function dropRole(mOptions: MigrationOptions) {
 }
 
 export function createRole(mOptions: MigrationOptions) {
-  const _create = (roleName: Name, roleOptions: RoleOptions = {}) => {
+  const _create: CreateRole = (roleName, roleOptions = {}) => {
     const options = formatRoleOptions({
       ...roleOptions,
       superuser: roleOptions.superuser || false,
@@ -98,7 +83,7 @@ export function createRole(mOptions: MigrationOptions) {
 }
 
 export function alterRole(mOptions: MigrationOptions) {
-  const _alter = (roleName: Name, roleOptions: RoleOptions = {}) => {
+  const _alter: AlterRole = (roleName, roleOptions = {}) => {
     const options = formatRoleOptions(roleOptions)
     return options ? `ALTER ROLE ${mOptions.literal(roleName)} WITH ${options};` : ''
   }
@@ -106,11 +91,11 @@ export function alterRole(mOptions: MigrationOptions) {
 }
 
 export function renameRole(mOptions: MigrationOptions) {
-  const _rename = (oldRoleName: Name, newRoleName: Name) => {
+  const _rename: RenameRole = (oldRoleName, newRoleName) => {
     const oldRoleNameStr = mOptions.literal(oldRoleName)
     const newRoleNameStr = mOptions.literal(newRoleName)
     return `ALTER ROLE ${oldRoleNameStr} RENAME TO ${newRoleNameStr};`
   }
-  _rename.reverse = (oldRoleName: Name, newRoleName: Name) => _rename(newRoleName, oldRoleName)
+  _rename.reverse = (oldRoleName, newRoleName) => _rename(newRoleName, oldRoleName)
   return _rename
 }
diff --git a/src/operations/rolesTypes.ts b/src/operations/rolesTypes.ts
new file mode 100644
index 0000000..3ef8e9a
--- /dev/null
+++ b/src/operations/rolesTypes.ts
@@ -0,0 +1,25 @@
+import { Name, Value, IfExistsOption } from './generalTypes'
+
+export interface RoleOptions {
+  superuser?: boolean
+  createdb?: boolean
+  createrole?: boolean
+  inherit?: boolean
+  login?: boolean
+  replication?: boolean
+  bypassrls?: boolean
+  limit?: number
+  password?: Value
+  encrypted?: boolean
+  valid?: Value
+  inRole?: string | string[]
+  role?: string | string[]
+  admin?: string | string[]
+}
+
+type CreateRoleFn = (roleName: Name, roleOptions?: RoleOptions & IfExistsOption) => string | string[]
+export type CreateRole = CreateRoleFn & { reverse: CreateRoleFn }
+export type DropRole = (roleName: Name, options?: IfExistsOption) => string | string[]
+export type AlterRole = (roleName: Name, roleOptions: RoleOptions) => string | string[]
+type RenameRoleFn = (oldRoleName: Name, newRoleName: Name) => string | string[]
+export type RenameRole = RenameRoleFn & { reverse: RenameRoleFn }
diff --git a/src/operations/schemas.ts b/src/operations/schemas.ts
index 9765135..e81cb16 100644
--- a/src/operations/schemas.ts
+++ b/src/operations/schemas.ts
@@ -1,12 +1,10 @@
-import { DropOptions, IfNotExistsOption, Name } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
+import { CreateSchema, DropSchema, RenameSchema } from './schemasTypes'
 
-export interface CreateSchemaOptions extends IfNotExistsOption {
-  authorization?: string
-}
+export { CreateSchema, DropSchema, RenameSchema }
 
 export function dropSchema(mOptions: MigrationOptions) {
-  const _drop = (schemaName: string, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropSchema = (schemaName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const schemaNameStr = mOptions.literal(schemaName)
@@ -16,7 +14,7 @@ export function dropSchema(mOptions: MigrationOptions) {
 }
 
 export function createSchema(mOptions: MigrationOptions) {
-  const _create = (schemaName: string, { ifNotExists, authorization }: CreateSchemaOptions = {}) => {
+  const _create: CreateSchema = (schemaName: string, { ifNotExists, authorization } = {}) => {
     const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : ''
     const schemaNameStr = mOptions.literal(schemaName)
     const authorizationStr = authorization ? ` AUTHORIZATION ${authorization}` : ''
@@ -27,11 +25,11 @@ export function createSchema(mOptions: MigrationOptions) {
 }
 
 export function renameSchema(mOptions: MigrationOptions) {
-  const _rename = (schemaName: Name, newSchemaName: Name) => {
+  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: Name, newSchemaName: Name) => _rename(newSchemaName, schemaName)
+  _rename.reverse = (schemaName, newSchemaName) => _rename(newSchemaName, schemaName)
   return _rename
 }
diff --git a/src/operations/schemasTypes.ts b/src/operations/schemasTypes.ts
new file mode 100644
index 0000000..6e89f82
--- /dev/null
+++ b/src/operations/schemasTypes.ts
@@ -0,0 +1,11 @@
+import { DropOptions, IfNotExistsOption } from './generalTypes'
+
+export interface CreateSchemaOptions extends IfNotExistsOption {
+  authorization?: string
+}
+
+type CreateSchemaFn = (schemaName: string, schemaOptions?: CreateSchemaOptions & DropOptions) => string | string[]
+export type CreateSchema = CreateSchemaFn & { reverse: CreateSchemaFn }
+export type DropSchema = (schemaName: string, dropOptions?: DropOptions) => string | string[]
+type RenameSchemaFn = (oldSchemaName: string, newSchemaName: string) => string | string[]
+export type RenameSchema = RenameSchemaFn & { reverse: RenameSchemaFn }
diff --git a/src/operations/sequences.ts b/src/operations/sequences.ts
index fc08266..0265c7f 100644
--- a/src/operations/sequences.ts
+++ b/src/operations/sequences.ts
@@ -1,30 +1,9 @@
-import { ColumnDefinitions, DropOptions, Name, Type } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { applyType } from '../utils'
+import { SequenceOptions, CreateSequence, DropSequence, AlterSequence, RenameSequence } from './sequencesTypes'
+import { ColumnDefinitions } from './tablesTypes'
 
-export interface SequenceOptions {
-  type?: Type
-  increment?: number
-  minvalue?: number | null | false
-  maxvalue?: number | null | false
-  start?: number
-  cache?: number
-  cycle?: boolean
-  owner?: string | null | false
-}
-
-export interface SequenceOptionsCreateEn {
-  temporary?: boolean
-  ifNotExists?: boolean
-}
-
-export interface SequenceOptionsAlterEn {
-  restart?: number | true
-}
-
-export type SequenceOptionsCreate = SequenceOptionsCreateEn & SequenceOptions
-
-export type SequenceOptionsAlter = SequenceOptionsAlterEn & SequenceOptions
+export { CreateSequence, DropSequence, AlterSequence, RenameSequence }
 
 export const parseSequenceOptions = (typeShorthands: ColumnDefinitions, options: SequenceOptions) => {
   const { type, increment, minvalue, maxvalue, start, cache, cycle, owner } = options
@@ -65,7 +44,7 @@ export const parseSequenceOptions = (typeShorthands: ColumnDefinitions, options:
 }
 
 export function dropSequence(mOptions: MigrationOptions) {
-  const _drop = (sequenceName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropSequence = (sequenceName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const sequenceNameStr = mOptions.literal(sequenceName)
@@ -75,7 +54,7 @@ export function dropSequence(mOptions: MigrationOptions) {
 }
 
 export function createSequence(mOptions: MigrationOptions) {
-  const _create = (sequenceName: Name, options: SequenceOptionsCreate = {}) => {
+  const _create: CreateSequence = (sequenceName, options = {}) => {
     const { temporary, ifNotExists } = options
     const temporaryStr = temporary ? ' TEMPORARY' : ''
     const ifNotExistsStr = ifNotExists ? ' IF NOT EXISTS' : ''
@@ -88,8 +67,8 @@ export function createSequence(mOptions: MigrationOptions) {
   return _create
 }
 
-export function alterSequence(mOptions: MigrationOptions) {
-  return (sequenceName: Name, options: SequenceOptionsAlter) => {
+export function alterSequence(mOptions: MigrationOptions): AlterSequence {
+  return (sequenceName, options) => {
     const { restart } = options
     const clauses = parseSequenceOptions(mOptions.typeShorthands, options)
     if (restart) {
@@ -105,11 +84,11 @@ export function alterSequence(mOptions: MigrationOptions) {
 }
 
 export function renameSequence(mOptions: MigrationOptions) {
-  const _rename = (sequenceName: Name, newSequenceName: Name) => {
+  const _rename: RenameSequence = (sequenceName, newSequenceName) => {
     const sequenceNameStr = mOptions.literal(sequenceName)
     const newSequenceNameStr = mOptions.literal(newSequenceName)
     return `ALTER SEQUENCE ${sequenceNameStr} RENAME TO ${newSequenceNameStr};`
   }
-  _rename.reverse = (sequenceName: Name, newSequenceName: Name) => _rename(newSequenceName, sequenceName)
+  _rename.reverse = (sequenceName, newSequenceName) => _rename(newSequenceName, sequenceName)
   return _rename
 }
diff --git a/src/operations/sequencesTypes.ts b/src/operations/sequencesTypes.ts
new file mode 100644
index 0000000..78e3c33
--- /dev/null
+++ b/src/operations/sequencesTypes.ts
@@ -0,0 +1,27 @@
+import { Name, Type, DropOptions, IfNotExistsOption } from './generalTypes'
+
+export interface SequenceOptions {
+  type?: Type
+  increment?: number
+  minvalue?: number | null | false
+  maxvalue?: number | null | false
+  start?: number
+  cache?: number
+  cycle?: boolean
+  owner?: string | null | false
+}
+
+export interface SequenceOptionsCreate extends SequenceOptions, IfNotExistsOption {
+  temporary?: boolean
+}
+
+export interface SequenceOptionsAlter extends SequenceOptions {
+  restart?: number | true
+}
+
+type CreateSequenceFn = (sequenceName: Name, sequenceOptions?: SequenceOptionsCreate & DropOptions) => string | string[]
+export type CreateSequence = CreateSequenceFn & { reverse: CreateSequenceFn }
+export type DropSequence = (sequenceName: Name, dropOptions?: DropOptions) => string | string[]
+export type AlterSequence = (sequenceName: Name, sequenceOptions: SequenceOptionsAlter) => string | string[]
+type RenameSequenceFn = (oldSequenceName: Name, newSequenceName: Name) => string | string[]
+export type RenameSequence = RenameSequenceFn & { reverse: RenameSequenceFn }
diff --git a/src/operations/tables.ts b/src/operations/tables.ts
index 0bba4d3..805f7c5 100644
--- a/src/operations/tables.ts
+++ b/src/operations/tables.ts
@@ -1,48 +1,43 @@
 import _ from 'lodash'
+import { MigrationOptions, Literal } from '../types'
+import { applyType, applyTypeAdapters, comment, escapeValue, formatLines } from '../utils'
+import { parseSequenceOptions } from './sequences'
 import {
-  AddOptions,
+  CreateTable,
+  DropTable,
+  AlterTable,
+  RenameTable,
+  AddColumns,
+  DropColumns,
+  AlterColumn,
+  RenameColumn,
+  CreateConstraint,
+  DropConstraint,
+  RenameConstraint,
+  ReferencesOptions,
+  ConstraintOptions,
+  LikeOptions,
+  Like,
   ColumnDefinition,
   ColumnDefinitions,
-  DropOptions,
-  Like,
-  LikeOptions,
-  Name,
-  ReferencesOptions,
-  Value,
-} from '../definitions'
-import { MigrationOptions } from '../migration-builder'
-import { applyType, applyTypeAdapters, comment, escapeValue, formatLines } from '../utils'
-import { parseSequenceOptions, SequenceOptions } from './sequences'
-
-export interface ForeignKeyOptions extends ReferencesOptions {
-  columns: Name | Name[]
+} from './tablesTypes'
+import { Name } from './generalTypes'
+
+export {
+  CreateTable,
+  DropTable,
+  AlterTable,
+  RenameTable,
+  AddColumns,
+  DropColumns,
+  AlterColumn,
+  RenameColumn,
+  CreateConstraint,
+  DropConstraint,
+  RenameConstraint,
 }
 
-export interface ConstraintOptions {
-  check?: string | string[]
-  unique?: Name | Array<Name | Name[]>
-  primaryKey?: Name | Name[]
-  foreignKeys?: ForeignKeyOptions | ForeignKeyOptions[]
-  exclude?: string
-  deferrable?: boolean
-  deferred?: boolean
-  comment?: string
-}
-
-export interface TableOptions {
-  temporary?: boolean
-  ifNotExists?: boolean
-  inherits?: Name
-  like?: Name | { table: Name; options?: LikeOptions }
-  constraints?: ConstraintOptions
-  comment?: string | null
-}
-
-export interface AlterTableOptions {
-  levelSecurity: 'DISABLE' | 'ENABLE' | 'FORCE' | 'NO FORCE'
-}
-
-const parseReferences = (options: ReferencesOptions, literal: (v: Name) => string) => {
+const parseReferences = (options: ReferencesOptions, literal: Literal) => {
   const { references, match, onDelete, onUpdate } = options
   const clauses: string[] = []
   clauses.push(
@@ -71,7 +66,7 @@ const parseColumns = (
   mOptions: MigrationOptions,
 ): {
   columns: string[]
-  constraints: { primaryKey?: string[] }
+  constraints: ConstraintOptions
   comments: string[]
 } => {
   const extendingTypeShorthands = mOptions.typeShorthands
@@ -169,12 +164,7 @@ const parseColumns = (
   }
 }
 
-const parseConstraints = (
-  table: Name,
-  options: ConstraintOptions,
-  optionName: string,
-  literal: (v: Name) => string,
-) => {
+const parseConstraints = (table: Name, options: ConstraintOptions, optionName: string, literal: Literal) => {
   const {
     check,
     unique,
@@ -243,7 +233,7 @@ const parseConstraints = (
   }
 }
 
-const parseLike = (like: Name | { table: Name; options?: LikeOptions }, literal: (v: Name) => string) => {
+const parseLike = (like: Name | { table: Name; options?: LikeOptions }, literal: Literal) => {
   const formatOptions = (name: 'INCLUDING' | 'EXCLUDING', options: Like | Like[]) =>
     (_.isArray(options) ? options : [options]).map(option => ` ${name} ${option}`).join('')
 
@@ -259,7 +249,7 @@ const parseLike = (like: Name | { table: Name; options?: LikeOptions }, literal:
 
 // TABLE
 export function dropTable(mOptions: MigrationOptions) {
-  const _drop = (tableName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropTable = (tableName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const tableNameStr = mOptions.literal(tableName)
@@ -269,7 +259,7 @@ export function dropTable(mOptions: MigrationOptions) {
 }
 
 export function createTable(mOptions: MigrationOptions) {
-  const _create = (tableName: Name, columns: ColumnDefinitions, options: TableOptions = {}) => {
+  const _create: CreateTable = (tableName, columns, options = {}) => {
     const {
       temporary,
       ifNotExists,
@@ -277,7 +267,7 @@ export function createTable(mOptions: MigrationOptions) {
       like,
       constraints: optionsConstraints = {},
       comment: tableComment,
-    }: TableOptions = options
+    } = options
     const { columns: columnLines, constraints: crossColumnConstraints, comments: columnComments = [] } = parseColumns(
       tableName,
       columns,
@@ -320,7 +310,7 @@ ${formatLines(tableDefinition)}
 }
 
 export function alterTable(mOptions: MigrationOptions) {
-  const _alter = (tableName: Name, options: AlterTableOptions) => {
+  const _alter: AlterTable = (tableName, options) => {
     const alterDefinition = []
     if (options.levelSecurity) {
       alterDefinition.push(`${options.levelSecurity} ROW LEVEL SECURITY`)
@@ -332,23 +322,9 @@ export function alterTable(mOptions: MigrationOptions) {
 }
 
 // COLUMNS
-export interface AlterColumnOptions {
-  type?: string
-  default?: Value
-  notNull?: boolean
-  allowNull?: boolean
-  collation?: string
-  using?: string
-  comment?: string | null
-  generated?: null | false | ({ precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions)
-}
 
 export function dropColumns(mOptions: MigrationOptions) {
-  const _drop = (
-    tableName: Name,
-    columns: string | string[] | ColumnDefinitions,
-    { ifExists, cascade }: DropOptions = {},
-  ) => {
+  const _drop: DropColumns = (tableName, columns, { ifExists, cascade } = {}) => {
     if (typeof columns === 'string') {
       columns = [columns] // eslint-disable-line no-param-reassign
     } else if (!_.isArray(columns) && typeof columns === 'object') {
@@ -366,7 +342,7 @@ ${columnsStr};`
 }
 
 export function addColumns(mOptions: MigrationOptions) {
-  const _add = (tableName: Name, columns: ColumnDefinitions, { ifNotExists }: AddOptions = {}) => {
+  const _add: AddColumns = (tableName, columns, { ifNotExists } = {}) => {
     const { columns: columnLines, comments: columnComments = [] } = parseColumns(tableName, columns, mOptions)
     const columnsStr = formatLines(columnLines, `  ADD ${ifNotExists ? 'IF NOT EXISTS ' : ''}`)
     const tableNameStr = mOptions.literal(tableName)
@@ -378,8 +354,8 @@ export function addColumns(mOptions: MigrationOptions) {
   return _add
 }
 
-export function alterColumn(mOptions: MigrationOptions) {
-  return (tableName: Name, columnName: string, options: AlterColumnOptions) => {
+export function alterColumn(mOptions: MigrationOptions): AlterColumn {
+  return (tableName, columnName, options) => {
     const {
       default: defaultValue,
       type,
@@ -431,40 +407,39 @@ export function alterColumn(mOptions: MigrationOptions) {
 }
 
 export function renameTable(mOptions: MigrationOptions) {
-  const _rename = (tableName: Name, newName: Name) => {
+  const _rename: RenameTable = (tableName, newName) => {
     const tableNameStr = mOptions.literal(tableName)
     const newNameStr = mOptions.literal(newName)
     return `ALTER TABLE ${tableNameStr} RENAME TO ${newNameStr};`
   }
-  _rename.reverse = (tableName: Name, newName: Name) => _rename(newName, tableName)
+  _rename.reverse = (tableName, newName) => _rename(newName, tableName)
   return _rename
 }
 
 export function renameColumn(mOptions: MigrationOptions) {
-  const _rename = (tableName: Name, columnName: string, newName: string) => {
+  const _rename: RenameColumn = (tableName, columnName, newName) => {
     const tableNameStr = mOptions.literal(tableName)
     const columnNameStr = mOptions.literal(columnName)
     const newNameStr = mOptions.literal(newName)
     return `ALTER TABLE ${tableNameStr} RENAME ${columnNameStr} TO ${newNameStr};`
   }
-  _rename.reverse = (tableName: Name, columnName: string, newName: string) => _rename(tableName, newName, columnName)
+  _rename.reverse = (tableName, columnName, newName) => _rename(tableName, newName, columnName)
   return _rename
 }
 
 export function renameConstraint(mOptions: MigrationOptions) {
-  const _rename = (tableName: Name, constraintName: string, newName: string) => {
+  const _rename: RenameConstraint = (tableName, constraintName, newName) => {
     const tableNameStr = mOptions.literal(tableName)
     const constraintNameStr = mOptions.literal(constraintName)
     const newNameStr = mOptions.literal(newName)
     return `ALTER TABLE ${tableNameStr} RENAME CONSTRAINT ${constraintNameStr} TO ${newNameStr};`
   }
-  _rename.reverse = (tableName: Name, constraintName: string, newName: string) =>
-    _rename(tableName, newName, constraintName)
+  _rename.reverse = (tableName, constraintName, newName) => _rename(tableName, newName, constraintName)
   return _rename
 }
 
 export function dropConstraint(mOptions: MigrationOptions) {
-  const _drop = (tableName: Name, constraintName: string, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropConstraint = (tableName, constraintName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const tableNameStr = mOptions.literal(tableName)
@@ -474,14 +449,19 @@ export function dropConstraint(mOptions: MigrationOptions) {
   return _drop
 }
 export function addConstraint(mOptions: MigrationOptions) {
-  const _add = (tableName: Name, constraintName: string | null, expression: string | ConstraintOptions) => {
+  const _add: CreateConstraint = (tableName, constraintName, expression) => {
     const { constraints, comments } =
       typeof expression === 'string'
         ? {
             constraints: [`${constraintName ? `CONSTRAINT ${mOptions.literal(constraintName)} ` : ''}${expression}`],
             comments: [],
           }
-        : parseConstraints(tableName, expression, constraintName, mOptions.literal)
+        : parseConstraints(
+            tableName,
+            expression as Exclude<typeof expression, string>,
+            constraintName,
+            mOptions.literal,
+          )
     const constraintStr = formatLines(constraints, '  ADD ')
     return [`ALTER TABLE ${mOptions.literal(tableName)}\n${constraintStr};`, ...comments].join('\n')
   }
diff --git a/src/operations/tablesTypes.ts b/src/operations/tablesTypes.ts
new file mode 100644
index 0000000..c1a7dc8
--- /dev/null
+++ b/src/operations/tablesTypes.ts
@@ -0,0 +1,112 @@
+import { Name, Value, IfNotExistsOption, DropOptions } from './generalTypes'
+import { SequenceOptions } from './sequencesTypes'
+
+export type Action = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT'
+
+export interface ReferencesOptions {
+  referencesConstraintName?: string
+  referencesConstraintComment?: string
+  references?: Name
+  onDelete?: Action
+  onUpdate?: Action
+  match?: 'FULL' | 'SIMPLE'
+}
+
+export interface ColumnDefinition extends ReferencesOptions {
+  type: string
+  collation?: string
+  unique?: boolean
+  primaryKey?: boolean
+  notNull?: boolean
+  default?: Value
+  check?: string
+  deferrable?: boolean
+  deferred?: boolean
+  comment?: string | null
+  generated?: { precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions
+}
+
+export interface ColumnDefinitions {
+  [name: string]: ColumnDefinition | string
+}
+
+export type Like = 'COMMENTS' | 'CONSTRAINTS' | 'DEFAULTS' | 'IDENTITY' | 'INDEXES' | 'STATISTICS' | 'STORAGE' | 'ALL'
+
+export interface LikeOptions {
+  including?: Like | Like[]
+  excluding?: Like | Like[]
+}
+
+export interface ForeignKeyOptions extends ReferencesOptions {
+  columns: Name | Name[]
+}
+
+export interface ConstraintOptions {
+  check?: string | string[]
+  unique?: Name | Array<Name | Name[]>
+  primaryKey?: Name | Name[]
+  foreignKeys?: ForeignKeyOptions | ForeignKeyOptions[]
+  exclude?: string
+  deferrable?: boolean
+  deferred?: boolean
+  comment?: string
+}
+
+export interface TableOptions extends IfNotExistsOption {
+  temporary?: boolean
+  inherits?: Name
+  like?: Name | { table: Name; options?: LikeOptions }
+  constraints?: ConstraintOptions
+  comment?: string | null
+}
+
+export interface AlterTableOptions {
+  levelSecurity: 'DISABLE' | 'ENABLE' | 'FORCE' | 'NO FORCE'
+}
+
+export interface AlterColumnOptions {
+  type?: string
+  default?: Value
+  notNull?: boolean
+  allowNull?: boolean
+  collation?: string
+  using?: string
+  comment?: string | null
+  generated?: null | false | ({ precedence: 'ALWAYS' | 'BY DEFAULT' } & SequenceOptions)
+}
+
+type CreateTableFn = (
+  tableName: Name,
+  columns: ColumnDefinitions,
+  options?: TableOptions & DropOptions,
+) => string | string[]
+export type CreateTable = CreateTableFn & { reverse: CreateTableFn }
+export type DropTable = (tableName: Name, dropOptions?: DropOptions) => string | string[]
+type RenameTableFn = (tableName: Name, newtableName: Name) => string | string[]
+export type RenameTable = RenameTableFn & { reverse: RenameTableFn }
+export type AlterTable = (tableName: Name, alterOptions: AlterTableOptions) => string | string[]
+
+type AddColumnsFn = (
+  tableName: Name,
+  newColumns: ColumnDefinitions,
+  addOptions?: IfNotExistsOption & DropOptions,
+) => string | string[]
+export type AddColumns = AddColumnsFn & { reverse: AddColumnsFn }
+export type DropColumns = (
+  tableName: Name,
+  columns: string | string[] | { [name: string]: any },
+  dropOptions?: DropOptions,
+) => string | string[]
+type RenameColumnFn = (tableName: Name, oldColumnName: string, newColumnName: string) => string | string[]
+export type RenameColumn = RenameColumnFn & { reverse: RenameColumnFn }
+export type AlterColumn = (tableName: Name, columnName: string, options: AlterColumnOptions) => string | string[]
+
+type CreateConstraintFn = (
+  tableName: Name,
+  constraintName: string | null,
+  expression: (string | ConstraintOptions) & DropOptions,
+) => string | string[]
+export type CreateConstraint = CreateConstraintFn & { reverse: CreateConstraintFn }
+export type DropConstraint = (tableName: Name, constraintName: string, options?: DropOptions) => string | string[]
+type RenameConstraintFn = (tableName: Name, oldConstraintName: string, newConstraintName: string) => string | string[]
+export type RenameConstraint = RenameConstraintFn & { reverse: RenameConstraintFn }
diff --git a/src/operations/triggers.ts b/src/operations/triggers.ts
index 1df4296..43f2119c 100644
--- a/src/operations/triggers.ts
+++ b/src/operations/triggers.ts
@@ -1,23 +1,15 @@
 import { isArray } from 'lodash'
-import { DropOptions, Name, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { escapeValue } from '../utils'
-import { createFunction, dropFunction, FunctionOptions } from './functions'
+import { createFunction, dropFunction } from './functions'
+import { Name, DropOptions, Value } from './generalTypes'
+import { CreateTrigger, DropTrigger, RenameTrigger, TriggerOptions } from './triggersTypes'
+import { FunctionOptions } from './functionsTypes'
 
-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
-}
+export { CreateTrigger, DropTrigger, RenameTrigger }
 
 export function dropTrigger(mOptions: MigrationOptions) {
-  const _drop = (tableName: Name, triggerName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropTrigger = (tableName, triggerName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const triggerNameStr = mOptions.literal(triggerName)
@@ -28,10 +20,10 @@ export function dropTrigger(mOptions: MigrationOptions) {
 }
 
 export function createTrigger(mOptions: MigrationOptions) {
-  const _create = (
+  const _create: CreateTrigger = (
     tableName: Name,
-    triggerName: Name,
-    triggerOptions: Partial<TriggerOptions & FunctionOptions> = {},
+    triggerName: string,
+    triggerOptions: TriggerOptions & FunctionOptions & DropOptions,
     definition?: Value,
   ) => {
     const { constraint, condition, operation, deferrable, deferred, functionParams = [] } = triggerOptions
@@ -80,8 +72,8 @@ export function createTrigger(mOptions: MigrationOptions) {
 
   _create.reverse = (
     tableName: Name,
-    triggerName: Name,
-    triggerOptions: Partial<TriggerOptions> & DropOptions = {},
+    triggerName: string,
+    triggerOptions: TriggerOptions & FunctionOptions & DropOptions,
     definition?: Value,
   ) => {
     const triggerSQL = dropTrigger(mOptions)(tableName, triggerName, triggerOptions)
@@ -95,13 +87,12 @@ export function createTrigger(mOptions: MigrationOptions) {
 }
 
 export function renameTrigger(mOptions: MigrationOptions) {
-  const _rename = (tableName: Name, oldTriggerName: Name, newTriggerName: Name) => {
+  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: Name, oldTriggerName: Name, newTriggerName: Name) =>
-    _rename(tableName, newTriggerName, oldTriggerName)
+  _rename.reverse = (tableName, oldTriggerName, newTriggerName) => _rename(tableName, newTriggerName, oldTriggerName)
   return _rename
 }
diff --git a/src/operations/triggersTypes.ts b/src/operations/triggersTypes.ts
new file mode 100644
index 0000000..1360111
--- /dev/null
+++ b/src/operations/triggersTypes.ts
@@ -0,0 +1,28 @@
+import { Name, Value, DropOptions } from './generalTypes'
+import { FunctionOptions } from './functionsTypes'
+
+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
+}
+
+interface CreateTriggerFn {
+  (tableName: Name, triggerName: string, triggerOptions: TriggerOptions & DropOptions): string | string[]
+  (
+    tableName: Name,
+    triggerName: string,
+    triggerOptions: TriggerOptions & FunctionOptions & DropOptions,
+    definition: Value,
+  ): string | string[]
+}
+export type CreateTrigger = CreateTriggerFn & { reverse: CreateTriggerFn }
+export type DropTrigger = (tableName: Name, triggerName: string, dropOptions?: DropOptions) => string | string[]
+type RenameTriggerFn = (tableName: Name, oldTriggerName: string, newTriggerName: string) => string | string[]
+export type RenameTrigger = RenameTriggerFn & { reverse: RenameTriggerFn }
diff --git a/src/operations/types.ts b/src/operations/types.ts
index 76f50dd..dbeeec1 100644
--- a/src/operations/types.ts
+++ b/src/operations/types.ts
@@ -1,10 +1,32 @@
 import _ from 'lodash'
-import { DropOptions, IfExistsOption, Name, Type, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { applyType, escapeValue } from '../utils'
+import {
+  CreateType,
+  DropType,
+  RenameType,
+  AddTypeAttribute,
+  DropTypeAttribute,
+  SetTypeAttribute,
+  AddTypeValue,
+  RenameTypeAttribute,
+  RenameTypeValue,
+} from './typesTypes'
+
+export {
+  CreateType,
+  DropType,
+  RenameType,
+  AddTypeAttribute,
+  DropTypeAttribute,
+  SetTypeAttribute,
+  AddTypeValue,
+  RenameTypeAttribute,
+  RenameTypeValue,
+}
 
 export function dropType(mOptions: MigrationOptions) {
-  const _drop = (typeName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropType = (typeName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const typeNameStr = mOptions.literal(typeName)
@@ -14,7 +36,7 @@ export function dropType(mOptions: MigrationOptions) {
 }
 
 export function createType(mOptions: MigrationOptions) {
-  const _create = (typeName: Name, options: Value[] | { [name: string]: Type }) => {
+  const _create: CreateType = (typeName, options) => {
     if (_.isArray(options)) {
       const optionsStr = options.map(escapeValue).join(', ')
       const typeNameStr = mOptions.literal(typeName)
@@ -31,7 +53,7 @@ export function createType(mOptions: MigrationOptions) {
 }
 
 export function dropTypeAttribute(mOptions: MigrationOptions) {
-  const _drop = (typeName: Name, attributeName: string, { ifExists }: IfExistsOption = {}) => {
+  const _drop: DropTypeAttribute = (typeName, attributeName, { ifExists } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const typeNameStr = mOptions.literal(typeName)
     const attributeNameStr = mOptions.literal(attributeName)
@@ -41,7 +63,7 @@ export function dropTypeAttribute(mOptions: MigrationOptions) {
 }
 
 export function addTypeAttribute(mOptions: MigrationOptions) {
-  const _alterAttributeAdd = (typeName: Name, attributeName: string, attributeType: Type) => {
+  const _alterAttributeAdd: AddTypeAttribute = (typeName, attributeName, attributeType) => {
     const typeStr = applyType(attributeType, mOptions.typeShorthands).type
     const typeNameStr = mOptions.literal(typeName)
     const attributeNameStr = mOptions.literal(attributeName)
@@ -52,8 +74,8 @@ export function addTypeAttribute(mOptions: MigrationOptions) {
   return _alterAttributeAdd
 }
 
-export function setTypeAttribute(mOptions: MigrationOptions) {
-  return (typeName: Name, attributeName: string, attributeType: Type) => {
+export function setTypeAttribute(mOptions: MigrationOptions): SetTypeAttribute {
+  return (typeName, attributeName, attributeType) => {
     const typeStr = applyType(attributeType, mOptions.typeShorthands).type
     const typeNameStr = mOptions.literal(typeName)
     const attributeNameStr = mOptions.literal(attributeName)
@@ -63,15 +85,7 @@ export function setTypeAttribute(mOptions: MigrationOptions) {
 }
 
 export function addTypeValue(mOptions: MigrationOptions) {
-  const _add = (
-    typeName: Name,
-    value: Value,
-    options: {
-      ifNotExists?: boolean
-      before?: string
-      after?: string
-    } = {},
-  ) => {
+  const _add: AddTypeValue = (typeName, value, options = {}) => {
     const { ifNotExists, before, after } = options
 
     if (before && after) {
@@ -89,34 +103,33 @@ export function addTypeValue(mOptions: MigrationOptions) {
 }
 
 export function renameType(mOptions: MigrationOptions) {
-  const _rename = (typeName: Name, newTypeName: Name) => {
+  const _rename: RenameType = (typeName, newTypeName) => {
     const typeNameStr = mOptions.literal(typeName)
     const newTypeNameStr = mOptions.literal(newTypeName)
     return `ALTER TYPE ${typeNameStr} RENAME TO ${newTypeNameStr};`
   }
-  _rename.reverse = (typeName: Name, newTypeName: Name) => _rename(newTypeName, typeName)
+  _rename.reverse = (typeName, newTypeName) => _rename(newTypeName, typeName)
   return _rename
 }
 
 export function renameTypeAttribute(mOptions: MigrationOptions) {
-  const _rename = (typeName: Name, attributeName: string, newAttributeName: string) => {
+  const _rename: RenameTypeAttribute = (typeName, attributeName, newAttributeName) => {
     const typeNameStr = mOptions.literal(typeName)
     const attributeNameStr = mOptions.literal(attributeName)
     const newAttributeNameStr = mOptions.literal(newAttributeName)
     return `ALTER TYPE ${typeNameStr} RENAME ATTRIBUTE ${attributeNameStr} TO ${newAttributeNameStr};`
   }
-  _rename.reverse = (typeName: Name, attributeName: string, newAttributeName: string) =>
-    _rename(typeName, newAttributeName, attributeName)
+  _rename.reverse = (typeName, attributeName, newAttributeName) => _rename(typeName, newAttributeName, attributeName)
   return _rename
 }
 
 export function renameTypeValue(mOptions: MigrationOptions) {
-  const _rename = (typeName: Name, value: string, newValue: string) => {
+  const _rename: RenameTypeValue = (typeName, value, newValue) => {
     const valueStr = escapeValue(value)
     const newValueStr = escapeValue(newValue)
     const typeNameStr = mOptions.literal(typeName)
     return `ALTER TYPE ${typeNameStr} RENAME VALUE ${valueStr} TO ${newValueStr};`
   }
-  _rename.reverse = (typeName: Name, value: string, newValue: string) => _rename(typeName, newValue, value)
+  _rename.reverse = (typeName, value, newValue) => _rename(typeName, newValue, value)
   return _rename
 }
diff --git a/src/operations/typesTypes.ts b/src/operations/typesTypes.ts
new file mode 100644
index 0000000..fbecd4a
--- /dev/null
+++ b/src/operations/typesTypes.ts
@@ -0,0 +1,25 @@
+import { Name, Value, Type, DropOptions, IfExistsOption, IfNotExistsOption } from './generalTypes'
+
+export interface AddTypeValueOptions extends IfNotExistsOption {
+  before?: string
+  after?: string
+}
+
+type CreateTypeFn = (typeName: Name, values: (Value[] | { [name: string]: Type }) & DropOptions) => string | string[]
+export type CreateType = CreateTypeFn & { reverse: CreateTypeFn }
+export type DropType = (typeName: Name, dropOptions?: DropOptions) => string | string[]
+type RenameTypeFn = (typeName: Name, newTypeName: Name) => string | string[]
+export type RenameType = RenameTypeFn & { reverse: RenameTypeFn }
+type AddTypeAttributeFn = (
+  typeName: Name,
+  attributeName: string,
+  attributeType: Type & IfExistsOption,
+) => string | string[]
+export type AddTypeAttribute = AddTypeAttributeFn & { reverse: AddTypeAttributeFn }
+export type DropTypeAttribute = (typeName: Name, attributeName: string, options: IfExistsOption) => string | string[]
+export type SetTypeAttribute = (typeName: Name, attributeName: string, attributeType: Type) => string | string[]
+export type AddTypeValue = (typeName: Name, value: Value, options?: AddTypeValueOptions) => string | string[]
+type RenameTypeAttributeFn = (typeName: Name, attributeName: string, newAttributeName: string) => string | string[]
+export type RenameTypeAttribute = RenameTypeAttributeFn & { reverse: RenameTypeAttributeFn }
+type RenameTypeValueFn = (typeName: Name, value: string, newValue: string) => string | string[]
+export type RenameTypeValue = RenameTypeValueFn & { reverse: RenameTypeValueFn }
diff --git a/src/operations/views.ts b/src/operations/views.ts
index a515bd3..ae46a37 100644
--- a/src/operations/views.ts
+++ b/src/operations/views.ts
@@ -1,25 +1,11 @@
-import { DropOptions, Name, Value } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { escapeValue } from '../utils'
+import { CreateView, DropView, AlterView, AlterViewColumn, RenameView } from './viewsTypes'
 
-export interface CreateViewOptions {
-  temporary?: boolean
-  replace?: boolean
-  recursive?: boolean
-  columns?: string | string[]
-  checkOption?: 'CASCADED' | 'LOCAL'
-}
-
-export interface AlterViewOptions {
-  checkOption?: null | false | 'CASCADED' | 'LOCAL'
-}
-
-export interface AlterViewColumnOptions {
-  default?: Value
-}
+export { CreateView, DropView, AlterView, AlterViewColumn, RenameView }
 
 export function dropView(mOptions: MigrationOptions) {
-  const _drop = (viewName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropView = (viewName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const viewNameStr = mOptions.literal(viewName)
@@ -29,7 +15,7 @@ export function dropView(mOptions: MigrationOptions) {
 }
 
 export function createView(mOptions: MigrationOptions) {
-  const _create = (viewName: Name, options: CreateViewOptions, definition: string) => {
+  const _create: CreateView = (viewName, options, definition) => {
     const { temporary, replace, recursive, columns = [], checkOption } = options
     // prettier-ignore
     const columnNames = (Array.isArray(columns) ? columns : [columns]).map(mOptions.literal).join(", ");
@@ -47,7 +33,7 @@ export function createView(mOptions: MigrationOptions) {
 }
 
 export function alterView(mOptions: MigrationOptions) {
-  const _alter = (viewName: Name, options: AlterViewOptions) => {
+  const _alter: AlterView = (viewName, options) => {
     const { checkOption } = options
     const clauses = []
     if (checkOption !== undefined) {
@@ -63,7 +49,7 @@ export function alterView(mOptions: MigrationOptions) {
 }
 
 export function alterViewColumn(mOptions: MigrationOptions) {
-  const _alter = (viewName: Name, columnName: Name, options: AlterViewColumnOptions) => {
+  const _alter: AlterViewColumn = (viewName, columnName, options) => {
     const { default: defaultValue } = options
     const actions = []
     if (defaultValue === null) {
@@ -79,11 +65,11 @@ export function alterViewColumn(mOptions: MigrationOptions) {
 }
 
 export function renameView(mOptions: MigrationOptions) {
-  const _rename = (viewName: Name, newViewName: Name) => {
+  const _rename: RenameView = (viewName, newViewName) => {
     const viewNameStr = mOptions.literal(viewName)
     const newViewNameStr = mOptions.literal(newViewName)
     return `ALTER VIEW ${viewNameStr} RENAME TO ${newViewNameStr};`
   }
-  _rename.reverse = (viewName: Name, newViewName: Name) => _rename(newViewName, viewName)
+  _rename.reverse = (viewName, newViewName) => _rename(newViewName, viewName)
   return _rename
 }
diff --git a/src/operations/viewsMaterialized.ts b/src/operations/viewsMaterialized.ts
index d41b0fb..ffe99f0 100644
--- a/src/operations/viewsMaterialized.ts
+++ b/src/operations/viewsMaterialized.ts
@@ -1,34 +1,32 @@
-import { DropOptions, Name } from '../definitions'
-import { MigrationOptions } from '../migration-builder'
+import { MigrationOptions } from '../types'
 import { formatLines } from '../utils'
+import {
+  StorageParameters,
+  CreateMaterializedView,
+  DropMaterializedView,
+  AlterMaterializedView,
+  RenameMaterializedView,
+  RenameMaterializedViewColumn,
+  RefreshMaterializedView,
+} from './viewsMaterializedTypes'
 
-export interface CreateMaterializedViewOptions {
-  ifNotExists?: boolean
-  columns?: string | string[]
-  tablespace?: string
-  storageParameters?: { [key: string]: any }
-  data?: boolean
-}
-
-export interface AlterMaterializedViewOptions {
-  cluster?: null | false | string
-  extension?: string
-  storageParameters?: { [key: string]: any }
-}
-
-export interface RefreshMaterializedViewOptions {
-  concurrently?: boolean
-  data?: boolean
+export {
+  CreateMaterializedView,
+  DropMaterializedView,
+  AlterMaterializedView,
+  RenameMaterializedView,
+  RenameMaterializedViewColumn,
+  RefreshMaterializedView,
 }
 
 const dataClause = (data?: boolean) => (data !== undefined ? ` WITH${data ? '' : ' NO'} DATA` : '')
-const storageParameterStr = <T extends { [key: string]: any }, K extends keyof T>(storageParameters: T) => (key: K) => {
+const storageParameterStr = <T extends StorageParameters, K extends keyof T>(storageParameters: T) => (key: K) => {
   const value = storageParameters[key] === true ? '' : ` = ${storageParameters[key]}`
   return `${key}${value}`
 }
 
 export function dropMaterializedView(mOptions: MigrationOptions) {
-  const _drop = (viewName: Name, { ifExists, cascade }: DropOptions = {}) => {
+  const _drop: DropMaterializedView = (viewName, { ifExists, cascade } = {}) => {
     const ifExistsStr = ifExists ? ' IF EXISTS' : ''
     const cascadeStr = cascade ? ' CASCADE' : ''
     const viewNameStr = mOptions.literal(viewName)
@@ -38,7 +36,7 @@ export function dropMaterializedView(mOptions: MigrationOptions) {
 }
 
 export function createMaterializedView(mOptions: MigrationOptions) {
-  const _create = (viewName: Name, options: CreateMaterializedViewOptions, definition: string) => {
+  const _create: CreateMaterializedView = (viewName, options, definition) => {
     const { ifNotExists, columns = [], tablespace, storageParameters = {}, data } = options
     // prettier-ignore
     const columnNames = (Array.isArray(columns) ? columns : [columns]).map(mOptions.literal).join(", ");
@@ -60,8 +58,8 @@ export function createMaterializedView(mOptions: MigrationOptions) {
 }
 
 export function alterMaterializedView(mOptions: MigrationOptions) {
-  const _alter = (viewName: Name, options: AlterMaterializedViewOptions) => {
-    const { cluster, extension, storageParameters = {} }: AlterMaterializedViewOptions = options
+  const _alter: AlterMaterializedView = (viewName, options) => {
+    const { cluster, extension, storageParameters = {} } = options
     const clauses = []
     if (cluster !== undefined) {
       if (cluster) {
@@ -94,29 +92,28 @@ export function alterMaterializedView(mOptions: MigrationOptions) {
 }
 
 export function renameMaterializedView(mOptions: MigrationOptions) {
-  const _rename = (viewName: Name, newViewName: Name) => {
+  const _rename: RenameMaterializedView = (viewName, newViewName) => {
     const viewNameStr = mOptions.literal(viewName)
     const newViewNameStr = mOptions.literal(newViewName)
     return `ALTER MATERIALIZED VIEW ${viewNameStr} RENAME TO ${newViewNameStr};`
   }
-  _rename.reverse = (viewName: Name, newViewName: Name) => _rename(newViewName, viewName)
+  _rename.reverse = (viewName, newViewName) => _rename(newViewName, viewName)
   return _rename
 }
 
 export function renameMaterializedViewColumn(mOptions: MigrationOptions) {
-  const _rename = (viewName: Name, columnName: string, newColumnName: string) => {
+  const _rename: RenameMaterializedViewColumn = (viewName, columnName, newColumnName) => {
     const viewNameStr = mOptions.literal(viewName)
     const columnNameStr = mOptions.literal(columnName)
     const newColumnNameStr = mOptions.literal(newColumnName)
     return `ALTER MATERIALIZED VIEW ${viewNameStr} RENAME COLUMN ${columnNameStr} TO ${newColumnNameStr};`
   }
-  _rename.reverse = (viewName: Name, columnName: string, newColumnName: string) =>
-    _rename(viewName, newColumnName, columnName)
+  _rename.reverse = (viewName, columnName, newColumnName) => _rename(viewName, newColumnName, columnName)
   return _rename
 }
 
 export function refreshMaterializedView(mOptions: MigrationOptions) {
-  const _refresh = (viewName: Name, { concurrently, data }: RefreshMaterializedViewOptions = {}) => {
+  const _refresh: RefreshMaterializedView = (viewName, { concurrently, data } = {}) => {
     const concurrentlyStr = concurrently ? ' CONCURRENTLY' : ''
     const dataStr = dataClause(data)
     const viewNameStr = mOptions.literal(viewName)
diff --git a/src/operations/viewsMaterializedTypes.ts b/src/operations/viewsMaterializedTypes.ts
new file mode 100644
index 0000000..5ffd781
--- /dev/null
+++ b/src/operations/viewsMaterializedTypes.ts
@@ -0,0 +1,36 @@
+import { Name, DropOptions, IfNotExistsOption } from './generalTypes'
+
+export type StorageParameters = { [key: string]: any }
+
+export interface CreateMaterializedViewOptions extends IfNotExistsOption {
+  columns?: string | string[]
+  tablespace?: string
+  storageParameters?: StorageParameters
+  data?: boolean
+}
+
+export interface AlterMaterializedViewOptions {
+  cluster?: null | false | string
+  extension?: string
+  storageParameters?: StorageParameters
+}
+
+export interface RefreshMaterializedViewOptions {
+  concurrently?: boolean
+  data?: boolean
+}
+
+type CreateMaterializedViewFn = (
+  viewName: Name,
+  options: CreateMaterializedViewOptions & DropOptions,
+  definition: string,
+) => string | string[]
+export type CreateMaterializedView = CreateMaterializedViewFn & { reverse: CreateMaterializedViewFn }
+export type DropMaterializedView = (viewName: Name, options?: DropOptions) => string | string[]
+export type AlterMaterializedView = (viewName: Name, options: AlterMaterializedViewOptions) => string | string[]
+type RenameMaterializedViewFn = (viewName: Name, newViewName: Name) => string | string[]
+export type RenameMaterializedView = RenameMaterializedViewFn & { reverse: RenameMaterializedViewFn }
+type RenameMaterializedViewColumnFn = (viewName: Name, columnName: string, newColumnName: string) => string | string[]
+export type RenameMaterializedViewColumn = RenameMaterializedViewColumnFn & { reverse: RenameMaterializedViewColumnFn }
+type RefreshMaterializedViewFn = (viewName: Name, options?: RefreshMaterializedViewOptions) => string | string[]
+export type RefreshMaterializedView = RefreshMaterializedViewFn & { reverse: RefreshMaterializedViewFn }
diff --git a/src/operations/viewsTypes.ts b/src/operations/viewsTypes.ts
new file mode 100644
index 0000000..8d878ad
--- /dev/null
+++ b/src/operations/viewsTypes.ts
@@ -0,0 +1,25 @@
+import { Name, Value, DropOptions } from './generalTypes'
+
+export interface CreateViewOptions {
+  temporary?: boolean
+  replace?: boolean
+  recursive?: boolean
+  columns?: string | string[]
+  checkOption?: 'CASCADED' | 'LOCAL'
+}
+
+export interface AlterViewOptions {
+  checkOption?: null | false | 'CASCADED' | 'LOCAL'
+}
+
+export interface AlterViewColumnOptions {
+  default?: Value
+}
+
+type CreateViewFn = (viewName: Name, options: CreateViewOptions & DropOptions, definition: string) => string | string[]
+export type CreateView = CreateViewFn & { reverse: CreateViewFn }
+export type DropView = (viewName: Name, options?: DropOptions) => string | string[]
+export type AlterView = (viewName: Name, options: AlterViewOptions) => string | string[]
+export type AlterViewColumn = (viewName: Name, columnName: string, options: AlterViewColumnOptions) => string | string[]
+type RenameViewFn = (viewName: Name, newViewName: Name) => string | string[]
+export type RenameView = RenameViewFn & { reverse: RenameViewFn }
diff --git a/src/runner.ts b/src/runner.ts
index a224282..1a9d802 100644
--- a/src/runner.ts
+++ b/src/runner.ts
@@ -1,13 +1,11 @@
 import fs from 'fs'
 import path from 'path'
 import { promisify } from 'util'
-import { Client } from 'pg'
-import { TlsOptions } from 'tls'
-import Db, { DB } from './db'
-import { ColumnDefinitions } from './definitions'
+import Db, { DBConnection } from './db'
+import { ColumnDefinitions } from './operations/tablesTypes'
 import { Migration, loadMigrationFiles, RunMigration } from './migration'
-import { MigrationBuilderActions } from './migration-builder'
-import { createSchemalize, getMigrationTableSchema, getSchemas, PgLiteral } from './utils'
+import { MigrationBuilderActions, MigrationDirection, RunnerOptionClient, RunnerOptionUrl, RunnerOption } from './types'
+import { createSchemalize, getMigrationTableSchema, getSchemas } from './utils'
 
 // Random but well-known identifier shared by all instances of node-pg-migrate
 const PG_MIGRATE_LOCK_ID = 7241865325823964
@@ -18,7 +16,7 @@ const idColumn = 'id'
 const nameColumn = 'name'
 const runOnColumn = 'run_on'
 
-const loadMigrations = async (db: DB, options: RunnerOption, log: typeof console.log) => {
+const loadMigrations = async (db: DBConnection, options: RunnerOption, log: typeof console.log) => {
   try {
     let shorthands: ColumnDefinitions = {}
     const files = await loadMigrationFiles(options.dir, options.ignorePattern)
@@ -47,14 +45,14 @@ const loadMigrations = async (db: DB, options: RunnerOption, log: typeof console
   }
 }
 
-const lock = async (db: DB): Promise<void> => {
+const lock = async (db: DBConnection): Promise<void> => {
   const [lockObtained] = await db.select(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as "lockObtained"`)
   if (!lockObtained) {
     throw new Error('Another migration is already running')
   }
 }
 
-const ensureMigrationsTable = async (db: DB, options: RunnerOption): Promise<void> => {
+const ensureMigrationsTable = async (db: DBConnection, options: RunnerOption): Promise<void> => {
   try {
     const schema = getMigrationTableSchema(options)
     const { migrationsTable } = options
@@ -87,7 +85,7 @@ const ensureMigrationsTable = async (db: DB, options: RunnerOption): Promise<voi
   }
 }
 
-const getRunMigrations = async (db: DB, options: RunnerOption) => {
+const getRunMigrations = async (db: DBConnection, options: RunnerOption) => {
   const schema = getMigrationTableSchema(options)
   const { migrationsTable } = options
   const fullTableName = createSchemalize(
@@ -135,56 +133,10 @@ const checkOrder = (runNames: string[], migrations: Migration[]) => {
   }
 }
 
-export type MigrationDirection = 'up' | 'down'
-
 const runMigrations = (toRun: Migration[], method: 'markAsRun' | 'apply', direction: MigrationDirection) =>
   toRun.reduce((promise, migration) => promise.then(() => migration[method](direction)), Promise.resolve())
 
-export interface RunnerOptionConfig {
-  migrationsTable: string
-  migrationsSchema?: string
-  schema?: string | string[]
-  dir: string
-  checkOrder?: boolean
-  direction: MigrationDirection
-  count: number
-  timestamp?: boolean
-  ignorePattern: string
-  file?: string
-  dryRun?: boolean
-  createSchema?: boolean
-  createMigrationsSchema?: boolean
-  singleTransaction?: boolean
-  noLock?: boolean
-  fake?: boolean
-  decamelize?: boolean
-  log?: (msg: string) => void
-}
-
-export interface ConnectionConfig {
-  user?: string
-  database?: string
-  password?: string
-  port?: number
-  host?: string
-  connectionString?: string
-}
-
-export interface ClientConfig extends ConnectionConfig {
-  ssl?: boolean | TlsOptions
-}
-
-export interface RunnerOptionUrl {
-  databaseUrl: string | ClientConfig
-}
-
-export interface RunnerOptionClient {
-  dbClient: Client
-}
-
-export type RunnerOption = RunnerOptionConfig & (RunnerOptionClient | RunnerOptionUrl)
-
-const runner = async (options: RunnerOption): Promise<RunMigration[]> => {
+export default async (options: RunnerOption): Promise<RunMigration[]> => {
   const log = options.log || console.log
   const db = Db((options as RunnerOptionClient).dbClient || (options as RunnerOptionUrl).databaseUrl, log)
   try {
@@ -250,6 +202,3 @@ const runner = async (options: RunnerOption): Promise<RunMigration[]> => {
     db.close()
   }
 }
-
-export { PgLiteral, Migration }
-export default runner
diff --git a/src/types.ts b/src/types.ts
new file mode 100644
index 0000000..2ecbdab
--- /dev/null
+++ b/src/types.ts
@@ -0,0 +1,227 @@
+import { Client } from 'pg'
+import { TlsOptions } from 'tls'
+import { DB } from './db'
+import { Name } from './operations/generalTypes'
+
+import * as domains from './operations/domainsTypes'
+import * as extensions from './operations/extensionsTypes'
+import * as functions from './operations/functionsTypes'
+import * as indexes from './operations/indexesTypes'
+import * as operators from './operations/operatorsTypes'
+import * as other from './operations/othersTypes'
+import * as policies from './operations/policiesTypes'
+import * as roles from './operations/rolesTypes'
+import * as schemas from './operations/schemasTypes'
+import * as sequences from './operations/sequencesTypes'
+import * as tables from './operations/tablesTypes'
+import * as triggers from './operations/triggersTypes'
+import * as types from './operations/typesTypes'
+import * as views from './operations/viewsTypes'
+import * as mViews from './operations/viewsMaterializedTypes'
+import PgLiteral from './operations/PgLiteral'
+
+export interface MigrationBuilder {
+  createExtension: (...args: Parameters<extensions.CreateExtension>) => void
+  dropExtension: (...args: Parameters<extensions.DropExtension>) => void
+  addExtension: (...args: Parameters<extensions.CreateExtension>) => void
+  createTable: (...args: Parameters<tables.CreateTable>) => void
+  dropTable: (...args: Parameters<tables.DropTable>) => void
+  renameTable: (...args: Parameters<tables.RenameTable>) => void
+  alterTable: (...args: Parameters<tables.AlterTable>) => void
+  addColumns: (...args: Parameters<tables.AddColumns>) => void
+  dropColumns: (...args: Parameters<tables.DropColumns>) => void
+  renameColumn: (...args: Parameters<tables.RenameColumn>) => void
+  alterColumn: (...args: Parameters<tables.AlterColumn>) => void
+  addColumn: (...args: Parameters<tables.AddColumns>) => void
+  dropColumn: (...args: Parameters<tables.DropColumns>) => void
+  addConstraint: (...args: Parameters<tables.CreateConstraint>) => void
+  dropConstraint: (...args: Parameters<tables.DropConstraint>) => void
+  renameConstraint: (...args: Parameters<tables.RenameConstraint>) => void
+  createConstraint: (...args: Parameters<tables.CreateConstraint>) => void
+  createType: (...args: Parameters<types.CreateType>) => void
+  dropType: (...args: Parameters<types.DropType>) => void
+  addType: (...args: Parameters<types.CreateType>) => void
+  renameType: (...args: Parameters<types.RenameType>) => void
+  renameTypeAttribute: (...args: Parameters<types.RenameTypeAttribute>) => void
+  renameTypeValue: (...args: Parameters<types.RenameTypeValue>) => void
+  addTypeAttribute: (...args: Parameters<types.AddTypeAttribute>) => void
+  dropTypeAttribute: (...args: Parameters<types.DropTypeAttribute>) => void
+  setTypeAttribute: (...args: Parameters<types.SetTypeAttribute>) => void
+  addTypeValue: (...args: Parameters<types.AddTypeValue>) => void
+  createIndex: (...args: Parameters<indexes.CreateIndex>) => void
+  dropIndex: (...args: Parameters<indexes.DropIndex>) => void
+  addIndex: (...args: Parameters<indexes.CreateIndex>) => void
+  createRole: (...args: Parameters<roles.CreateRole>) => void
+  dropRole: (...args: Parameters<roles.DropRole>) => void
+  alterRole: (...args: Parameters<roles.AlterRole>) => void
+  renameRole: (...args: Parameters<roles.RenameRole>) => void
+  createFunction: (...args: Parameters<functions.CreateFunction>) => void
+  dropFunction: (...args: Parameters<functions.DropFunction>) => void
+  renameFunction: (...args: Parameters<functions.RenameFunction>) => void
+  createTrigger: (...args: Parameters<triggers.CreateTrigger>) => void
+  dropTrigger: (...args: Parameters<triggers.DropTrigger>) => void
+  renameTrigger: (...args: Parameters<triggers.RenameTrigger>) => void
+  createSchema: (...args: Parameters<schemas.CreateSchema>) => void
+  dropSchema: (...args: Parameters<schemas.DropSchema>) => void
+  renameSchema: (...args: Parameters<schemas.RenameSchema>) => void
+  createDomain: (...args: Parameters<domains.CreateDomain>) => void
+  dropDomain: (...args: Parameters<domains.DropDomain>) => void
+  alterDomain: (...args: Parameters<domains.AlterDomain>) => void
+  renameDomain: (...args: Parameters<domains.RenameDomain>) => void
+  createSequence: (...args: Parameters<sequences.CreateSequence>) => void
+  dropSequence: (...args: Parameters<sequences.DropSequence>) => void
+  alterSequence: (...args: Parameters<sequences.AlterSequence>) => void
+  renameSequence: (...args: Parameters<sequences.RenameSequence>) => void
+  createOperator: (...args: Parameters<operators.CreateOperator>) => void
+  dropOperator: (...args: Parameters<operators.DropOperator>) => void
+  createOperatorClass: (...args: Parameters<operators.CreateOperatorClass>) => void
+  dropOperatorClass: (...args: Parameters<operators.DropOperatorClass>) => void
+  renameOperatorClass: (...args: Parameters<operators.RenameOperatorClass>) => void
+  createOperatorFamily: (...args: Parameters<operators.CreateOperatorFamily>) => void
+  dropOperatorFamily: (...args: Parameters<operators.DropOperatorFamily>) => void
+  renameOperatorFamily: (...args: Parameters<operators.RenameOperatorFamily>) => void
+  addToOperatorFamily: (...args: Parameters<operators.AddToOperatorFamily>) => void
+  removeFromOperatorFamily: (...args: Parameters<operators.RemoveFromOperatorFamily>) => void
+  createPolicy: (...args: Parameters<policies.CreatePolicy>) => void
+  dropPolicy: (...args: Parameters<policies.DropPolicy>) => void
+  alterPolicy: (...args: Parameters<policies.AlterPolicy>) => void
+  renamePolicy: (...args: Parameters<policies.RenamePolicy>) => void
+  createView: (...args: Parameters<views.CreateView>) => void
+  dropView: (...args: Parameters<views.DropView>) => void
+  alterView: (...args: Parameters<views.AlterView>) => void
+  alterViewColumn: (...args: Parameters<views.AlterViewColumn>) => void
+  renameView: (...args: Parameters<views.RenameView>) => void
+  createMaterializedView: (...args: Parameters<mViews.CreateMaterializedView>) => void
+  dropMaterializedView: (...args: Parameters<mViews.DropMaterializedView>) => void
+  alterMaterializedView: (...args: Parameters<mViews.AlterMaterializedView>) => void
+  renameMaterializedView: (...args: Parameters<mViews.RenameMaterializedView>) => void
+  renameMaterializedViewColumn: (...args: Parameters<mViews.RenameMaterializedViewColumn>) => void
+  refreshMaterializedView: (...args: Parameters<mViews.RefreshMaterializedView>) => void
+  sql: (...args: Parameters<other.Sql>) => void
+  func: (sql: string) => PgLiteral
+  noTransaction: () => void
+  db: DB
+}
+
+export type MigrationAction = (pgm: MigrationBuilder, run?: () => void) => Promise<void> | void
+export type Literal = (v: Name) => string
+
+export interface MigrationBuilderActions {
+  up?: MigrationAction
+  down?: MigrationAction
+  shorthands?: tables.ColumnDefinitions
+}
+
+export interface MigrationOptions {
+  typeShorthands: tables.ColumnDefinitions
+  schemalize: Literal
+  literal: Literal
+}
+
+// Note these currently don't contain the parameterized types like
+// bit(n), varchar(n) and so on, they have to be specified as strings
+export enum PgType { // eslint-disable-line import/prefer-default-export
+  BIGINT = 'bigint', // signed eight-byte integer
+  INT8 = 'int8', // alias for bigint
+  BIGSERIAL = 'bigserial', // autoincrementing eight-byte integer
+  BIT_1 = 'bit', // fixed-length bit string
+  BIT_VARYING = 'bit varying', // variable-length bit string
+  VARBIT = 'varbit', // alias for bit varying
+  SERIAL8 = 'serial8', // alias for bigserial
+  BOOLEAN = 'boolean', // logical Boolean (true/false)
+  BOOL = 'bool', // alias for boolean
+  BOX = 'box', // rectangular box on a plane
+  BYTEA = 'bytea', // binary data ("byte array")
+  CHARACTER = 'character', // fixed-length character string
+  CHAR = 'char', // alias for character
+  CHARACTER_VARYING = 'character varying', // variable-length character string
+  VARCHAR = 'varchar', // alias for character varying
+  CIDR = 'cidr', // IPv4 or IPv6 network address
+  CIRCLE = 'circle', // circle on a plane
+  DATE = 'date', // calendar date (year, month, day)
+  DOUBLE_PRECISION = 'double precision', // float8	double precision floating-point number (8 bytes)
+  INET = 'inet', // IPv4 or IPv6 host address
+  INTEGER = 'integer', // signed four-byte integer
+  INT = 'int', // alias for int
+  INT4 = 'int4', // alias for int
+  INTERVAL = 'interval', // time span
+  JSON = 'json', // textual JSON data
+  JSONB = 'jsonb', // binary JSON data, decomposed
+  LINE = 'line', // infinite line on a plane
+  LSEG = 'lseg', // line segment on a plane
+  MACADDR = 'macaddr', // MAC (Media Access Control) address
+  MONEY = 'money', // currency amount
+  NUMERIC = 'numeric', // exact numeric of selectable precision
+  PATH = 'path', // geometric path on a plane
+  PG_LSN = 'pg_lsn', // PostgreSQL Log Sequence Number
+  POINT = 'point', // geometric point on a plane
+  POLYGON = 'polygon', // closed geometric path on a plane
+  REAL = 'real', // single precision floating-point number (4 bytes)
+  FLOAT4 = 'float4', // alias for REAL
+  SMALLINT = 'smallint', // signed two-byte integer
+  INT2 = 'int2', // alias for smallint
+  SMALLSERIAL = 'smallserial', // autoincrementing two-byte integer
+  SERIAL2 = 'serial2', // alias for smallserial
+  SERIAL = 'serial', // autoincrementing four-byte integer
+  SERIAL4 = 'serial4', // alias for serial
+  TEXT = 'text', // variable-length character string
+  TIME = 'time', // time of day (no time zone)
+  TIME_WITHOUT_TIME_ZONE = 'without time zone', // alias of time
+  TIME_WITH_TIME_ZONE = 'time with time zone', // time of day, including time zone
+  TIMETZ = 'timetz', // alias of time with time zone
+  TIMESTAMP = 'timestamp', // date and time (no time zone)
+  TIMESTAMP_WITHOUT_TIME_ZONE = 'timestamp without time zone', // alias of timestamp
+  TIMESTAMP_WITH_TIME_ZONE = 'timestamp with time zone', // date and time, including time zone
+  TIMESTAMPTZ = 'timestamptz', // alias of timestamp with time zone
+  TSQUERY = 'tsquery', // text search query
+  TSVECTOR = 'tsvector', // text search document
+  TXID_SNAPSHOT = 'txid_snapshot', // user-level transaction ID snapshot
+  UUID = 'uuid', // universally unique identifier
+  XML = 'xml', // XML data
+}
+
+export type MigrationDirection = 'up' | 'down'
+
+export interface RunnerOptionConfig {
+  migrationsTable: string
+  migrationsSchema?: string
+  schema?: string | string[]
+  dir: string
+  checkOrder?: boolean
+  direction: MigrationDirection
+  count: number
+  timestamp?: boolean
+  ignorePattern: string
+  file?: string
+  dryRun?: boolean
+  createSchema?: boolean
+  createMigrationsSchema?: boolean
+  singleTransaction?: boolean
+  noLock?: boolean
+  fake?: boolean
+  decamelize?: boolean
+  log?: (msg: string) => void
+}
+
+export interface ConnectionConfig {
+  user?: string
+  database?: string
+  password?: string
+  port?: number
+  host?: string
+  connectionString?: string
+}
+
+export interface ClientConfig extends ConnectionConfig {
+  ssl?: boolean | TlsOptions
+}
+
+export interface RunnerOptionUrl {
+  databaseUrl: string | ClientConfig
+}
+
+export interface RunnerOptionClient {
+  dbClient: Client
+}
+
+export type RunnerOption = RunnerOptionConfig & (RunnerOptionClient | RunnerOptionUrl)
diff --git a/src/utils.ts b/src/utils.ts
index 7e89556..7f7ddd3 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,32 +1,15 @@
 import decamelize from 'decamelize'
-import { ColumnDefinition, ColumnDefinitions, Name, Type, Value } from './definitions'
-import { MigrationOptions } from './migration-builder'
-import { FunctionParam, FunctionParamType } from './operations/functions'
-import { RunnerOption } from './runner'
-
-// This is used to create unescaped strings
-// exposed in the migrations via pgm.func
-export class PgLiteral {
-  static create(str: string): PgLiteral {
-    return new PgLiteral(str)
-  }
-
-  private readonly _str: string
-
-  constructor(str: string) {
-    this._str = str
-  }
-
-  toString(): string {
-    return this._str
-  }
-}
+import { ColumnDefinitions, ColumnDefinition } from './operations/tablesTypes'
+import { Name, Type, Value } from './operations/generalTypes'
+import { MigrationOptions, Literal, RunnerOption } from './types'
+import { FunctionParam, FunctionParamType } from './operations/functionsTypes'
+import PgLiteral from './operations/PgLiteral'
 
 const identity = <T>(v: T) => v
 const quote = (str: string) => `"${str}"`
 
 export const createSchemalize = (shouldDecamelize: boolean, shouldQuote: boolean) => {
-  const transform: (v: Name) => string = [
+  const transform: Literal = [
     shouldDecamelize ? decamelize : identity,
     shouldQuote ? quote : identity,
   ].reduce((acc, fn) => (fn === identity ? acc : x => acc(fn(x))))
@@ -39,7 +22,7 @@ export const createSchemalize = (shouldDecamelize: boolean, shouldQuote: boolean
   }
 }
 
-export const createTransformer = (literal: (v: Name) => string) => (s: string, d?: { [key: string]: Name }) =>
+export const createTransformer = (literal: Literal) => (s: string, d?: { [key: string]: Name }) =>
   Object.keys(d || {}).reduce(
     (str: string, p) => str.replace(new RegExp(`{${p}}`, 'g'), literal(d[p])), // eslint-disable-line security/detect-non-literal-regexp
     s,


Test patch:
diff --git a/test/migration-test.ts b/test/migration-test.ts
index da9fe1e..7d23ac9 100644
--- a/test/migration-test.ts
+++ b/test/migration-test.ts
@@ -1,9 +1,9 @@
 /* eslint-disable no-unused-expressions */
 import sinon, { SinonSpy } from 'sinon'
 import { expect } from 'chai'
-import { RunnerOption } from '../src/runner'
+import { RunnerOption } from '../src/types'
 import { Migration } from '../src/migration'
-import { DB } from '../src/db'
+import { DBConnection } from '../src/db'
 
 const callbackMigration = '1414549381268_names.js'
 const promiseMigration = '1414549381268_names_promise.js'
@@ -13,7 +13,7 @@ const actionsCallback = require(`./${callbackMigration}`) // eslint-disable-line
 const actionsPromise = require(`./${promiseMigration}`) // eslint-disable-line import/no-dynamic-require,security/detect-non-literal-require,@typescript-eslint/no-var-requires
 
 describe('lib/migration', () => {
-  const dbMock = {} as DB
+  const dbMock = {} as DBConnection
   const log: typeof console.log = () => null
   const options = { migrationsTable } as RunnerOption
   let migration
diff --git a/test/utils-test.ts b/test/utils-test.ts
index 2049b76..0d21856 100644
--- a/test/utils-test.ts
+++ b/test/utils-test.ts
@@ -1,6 +1,7 @@
 import { expect } from 'chai'
-import { escapeValue, PgLiteral, applyType } from '../src/utils'
-import { ColumnDefinitions } from '../src/definitions'
+import { escapeValue, applyType } from '../src/utils'
+import { ColumnDefinitions } from '../src/operations/tablesTypes'
+import PgLiteral from '../src/operations/PgLiteral'
 
 describe('lib/utils', () => {
   describe('.escapeValue', () => {