UNPKG

node-pg-migrate

Version:

PostgreSQL database migration management tool for node.js

600 lines (599 loc) 21.2 kB
import type { DB } from './db'; import type { Logger } from './logger'; import * as casts from './operations/casts'; import * as domains from './operations/domains'; import * as extensions from './operations/extensions'; import * as functions from './operations/functions'; import * as grants from './operations/grants'; import * as indexes from './operations/indexes'; import * as mViews from './operations/materializedViews'; import * as operators from './operations/operators'; import * as policies from './operations/policies'; import * as roles from './operations/roles'; import * as schemas from './operations/schemas'; import * as sequences from './operations/sequences'; import * as sql from './operations/sql'; import type { ColumnDefinitions } from './operations/tables'; import * as tables from './operations/tables'; import * as triggers from './operations/triggers'; import * as types from './operations/types'; import * as views from './operations/views'; import { PgLiteral } from './utils'; export declare class MigrationBuilder { /** * Install an extension. * * @alias addExtension * * @see https://www.postgresql.org/docs/current/sql-createextension.html */ readonly createExtension: (...args: Parameters<extensions.CreateExtension>) => void; /** * Remove an extension. * * @see https://www.postgresql.org/docs/current/sql-dropextension.html */ readonly dropExtension: (...args: Parameters<extensions.DropExtension>) => void; /** * Install an extension. * * @alias createExtension * * @see https://www.postgresql.org/docs/current/sql-createextension.html */ readonly addExtension: (...args: Parameters<extensions.CreateExtension>) => void; /** * Define a new table. * * @see https://www.postgresql.org/docs/current/sql-createtable.html */ readonly createTable: (...args: Parameters<tables.CreateTable>) => void; /** * Remove a table. * * @see https://www.postgresql.org/docs/current/sql-droptable.html */ readonly dropTable: (...args: Parameters<tables.DropTable>) => void; /** * Rename a table. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly renameTable: (...args: Parameters<tables.RenameTable>) => void; /** * Change the definition of a table. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly alterTable: (...args: Parameters<tables.AlterTable>) => void; /** * Add columns to a table. * * @alias addColumn * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly addColumns: (...args: Parameters<tables.AddColumns>) => void; /** * Remove columns from a table. * * @alias dropColumn * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly dropColumns: (...args: Parameters<tables.DropColumns>) => void; /** * Rename a column. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly renameColumn: (...args: Parameters<tables.RenameColumn>) => void; /** * Change the definition of a column. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly alterColumn: (...args: Parameters<tables.AlterColumn>) => void; /** * Add a column to a table. * * @alias addColumns * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly addColumn: (...args: Parameters<tables.AddColumns>) => void; /** * Remove a column from a table. * * @alias dropColumns * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly dropColumn: (...args: Parameters<tables.DropColumns>) => void; /** * Add a constraint to a table. * * @alias createConstraint * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly addConstraint: (...args: Parameters<tables.CreateConstraint>) => void; /** * Remove a constraint from a table. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly dropConstraint: (...args: Parameters<tables.DropConstraint>) => void; /** * Rename a constraint. * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly renameConstraint: (...args: Parameters<tables.RenameConstraint>) => void; /** * Add a constraint to a table. * * @alias addConstraint * * @see https://www.postgresql.org/docs/current/sql-altertable.html */ readonly createConstraint: (...args: Parameters<tables.CreateConstraint>) => void; /** * Define a new data type. * * @alias addType * * @see https://www.postgresql.org/docs/current/sql-createtype.html */ readonly createType: (...args: Parameters<types.CreateType>) => void; /** * Remove a data type. * * @see https://www.postgresql.org/docs/current/sql-droptype.html */ readonly dropType: (...args: Parameters<types.DropType>) => void; /** * Define a new data type. * * @alias createType * * @see https://www.postgresql.org/docs/current/sql-createtype.html */ readonly addType: (...args: Parameters<types.CreateType>) => void; /** * Rename a data type. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly renameType: (...args: Parameters<types.RenameType>) => void; /** * Rename a data type attribute. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly renameTypeAttribute: (...args: Parameters<types.RenameTypeAttribute>) => void; /** * Rename a data type value. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly renameTypeValue: (...args: Parameters<types.RenameTypeValue>) => void; /** * Add an attribute to a data type. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly addTypeAttribute: (...args: Parameters<types.AddTypeAttribute>) => void; /** * Remove an attribute from a data type. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly dropTypeAttribute: (...args: Parameters<types.DropTypeAttribute>) => void; /** * Set an attribute of a data type. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly setTypeAttribute: (...args: Parameters<types.SetTypeAttribute>) => void; /** * Add a value to a data type. * * @see https://www.postgresql.org/docs/current/sql-altertype.html */ readonly addTypeValue: (...args: Parameters<types.AddTypeValue>) => void; /** * Define a new index. * * @alias addIndex * * @see https://www.postgresql.org/docs/current/sql-createindex.html */ readonly createIndex: (...args: Parameters<indexes.CreateIndex>) => void; /** * Remove an index. * * @see https://www.postgresql.org/docs/current/sql-dropindex.html */ readonly dropIndex: (...args: Parameters<indexes.DropIndex>) => void; /** * Define a new index. * * @alias createIndex * * @see https://www.postgresql.org/docs/current/sql-createindex.html */ readonly addIndex: (...args: Parameters<indexes.CreateIndex>) => void; /** * Define a new database role. * * @see https://www.postgresql.org/docs/current/sql-createrole.html */ readonly createRole: (...args: Parameters<roles.CreateRole>) => void; /** * Remove a database role. * * @see https://www.postgresql.org/docs/current/sql-droprole.html */ readonly dropRole: (...args: Parameters<roles.DropRole>) => void; /** * Change a database role. * * @see https://www.postgresql.org/docs/current/sql-alterrole.html */ readonly alterRole: (...args: Parameters<roles.AlterRole>) => void; /** * Rename a database role. * * @see https://www.postgresql.org/docs/current/sql-alterrole.html */ readonly renameRole: (...args: Parameters<roles.RenameRole>) => void; /** * Define a new function. * * @see https://www.postgresql.org/docs/current/sql-createfunction.html */ readonly createFunction: (...args: Parameters<functions.CreateFunction>) => void; /** * Remove a function. * * @see https://www.postgresql.org/docs/current/sql-dropfunction.html */ readonly dropFunction: (...args: Parameters<functions.DropFunction>) => void; /** * Rename a function. * * @see https://www.postgresql.org/docs/current/sql-alterfunction.html */ readonly renameFunction: (...args: Parameters<functions.RenameFunction>) => void; /** * Define a new trigger. * * @see https://www.postgresql.org/docs/current/sql-createtrigger.html */ readonly createTrigger: (...args: Parameters<triggers.CreateTrigger>) => void; /** * Remove a trigger. * * @see https://www.postgresql.org/docs/current/sql-droptrigger.html */ readonly dropTrigger: (...args: Parameters<triggers.DropTrigger>) => void; /** * Rename a trigger. * * @see https://www.postgresql.org/docs/current/sql-altertrigger.html */ readonly renameTrigger: (...args: Parameters<triggers.RenameTrigger>) => void; /** * Define a new schema. * * @see https://www.postgresql.org/docs/current/sql-createschema.html */ readonly createSchema: (...args: Parameters<schemas.CreateSchema>) => void; /** * Remove a schema. * * @see https://www.postgresql.org/docs/current/sql-dropschema.html */ readonly dropSchema: (...args: Parameters<schemas.DropSchema>) => void; /** * Rename a schema. * * @see https://www.postgresql.org/docs/current/sql-alterschema.html */ readonly renameSchema: (...args: Parameters<schemas.RenameSchema>) => void; /** * Define a new domain. * * @see https://www.postgresql.org/docs/current/sql-createdomain.html */ readonly createDomain: (...args: Parameters<domains.CreateDomain>) => void; /** * Remove a domain. * * @see https://www.postgresql.org/docs/current/sql-dropdomain.html */ readonly dropDomain: (...args: Parameters<domains.DropDomain>) => void; /** * Change the definition of a domain. * * @see https://www.postgresql.org/docs/current/sql-alterdomain.html */ readonly alterDomain: (...args: Parameters<domains.AlterDomain>) => void; /** * Rename a domain. * * @see https://www.postgresql.org/docs/current/sql-alterdomain.html */ readonly renameDomain: (...args: Parameters<domains.RenameDomain>) => void; /** * Define a new sequence generator. * * @see https://www.postgresql.org/docs/current/sql-createsequence.html */ readonly createSequence: (...args: Parameters<sequences.CreateSequence>) => void; /** * Remove a sequence. * * @see https://www.postgresql.org/docs/current/sql-dropsequence.html */ readonly dropSequence: (...args: Parameters<sequences.DropSequence>) => void; /** * Change the definition of a sequence generator. * * @see https://www.postgresql.org/docs/current/sql-altersequence.html */ readonly alterSequence: (...args: Parameters<sequences.AlterSequence>) => void; /** * Rename a sequence. * * @see https://www.postgresql.org/docs/current/sql-altersequence.html */ readonly renameSequence: (...args: Parameters<sequences.RenameSequence>) => void; /** * Define a new operator. * * @see https://www.postgresql.org/docs/current/sql-createoperator.html */ readonly createOperator: (...args: Parameters<operators.CreateOperator>) => void; /** * Remove an operator. * * @see https://www.postgresql.org/docs/current/sql-dropoperator.html */ readonly dropOperator: (...args: Parameters<operators.DropOperator>) => void; /** * Define a new operator class. * * @see https://www.postgresql.org/docs/current/sql-createopclass.html */ readonly createOperatorClass: (...args: Parameters<operators.CreateOperatorClass>) => void; /** * Remove an operator class. * * @see https://www.postgresql.org/docs/current/sql-dropopclass.html */ readonly dropOperatorClass: (...args: Parameters<operators.DropOperatorClass>) => void; /** * Rename an operator class. * * @see https://www.postgresql.org/docs/current/sql-alteropclass.html */ readonly renameOperatorClass: (...args: Parameters<operators.RenameOperatorClass>) => void; /** * Define a new operator family. * * @see https://www.postgresql.org/docs/current/sql-createopfamily.html */ readonly createOperatorFamily: (...args: Parameters<operators.CreateOperatorFamily>) => void; /** * Remove an operator family. * * @see https://www.postgresql.org/docs/current/sql-dropopfamily.html */ readonly dropOperatorFamily: (...args: Parameters<operators.DropOperatorFamily>) => void; /** * Rename an operator family. * * @see https://www.postgresql.org/docs/current/sql-alteropfamily.html */ readonly renameOperatorFamily: (...args: Parameters<operators.RenameOperatorFamily>) => void; /** * Add an operator to an operator family. * * @see https://www.postgresql.org/docs/current/sql-alteropfamily.html */ readonly addToOperatorFamily: (...args: Parameters<operators.AddToOperatorFamily>) => void; /** * Remove an operator from an operator family. * * @see https://www.postgresql.org/docs/current/sql-alteropfamily.html */ readonly removeFromOperatorFamily: (...args: Parameters<operators.RemoveFromOperatorFamily>) => void; /** * Define a new row-level security policy for a table. * * @see https://www.postgresql.org/docs/current/sql-createpolicy.html */ readonly createPolicy: (...args: Parameters<policies.CreatePolicy>) => void; /** * Remove a row-level security policy from a table. * * @see https://www.postgresql.org/docs/current/sql-droppolicy.html */ readonly dropPolicy: (...args: Parameters<policies.DropPolicy>) => void; /** * Change the definition of a row-level security policy. * * @see https://www.postgresql.org/docs/current/sql-alterpolicy.html */ readonly alterPolicy: (...args: Parameters<policies.AlterPolicy>) => void; /** * Rename a row-level security policy. * * @see https://www.postgresql.org/docs/current/sql-alterpolicy.html */ readonly renamePolicy: (...args: Parameters<policies.RenamePolicy>) => void; /** * Define a new view. * * @see https://www.postgresql.org/docs/current/sql-createview.html */ readonly createView: (...args: Parameters<views.CreateView>) => void; /** * Remove a view. * * @see https://www.postgresql.org/docs/current/sql-dropview.html */ readonly dropView: (...args: Parameters<views.DropView>) => void; /** * Change the definition of a view. * * @see https://www.postgresql.org/docs/current/sql-alterview.html */ readonly alterView: (...args: Parameters<views.AlterView>) => void; /** * Change the definition of a view column. * * @see https://www.postgresql.org/docs/current/sql-alterview.html */ readonly alterViewColumn: (...args: Parameters<views.AlterViewColumn>) => void; /** * Rename a view. * * @see https://www.postgresql.org/docs/current/sql-alterview.html */ readonly renameView: (...args: Parameters<views.RenameView>) => void; /** * Define a new materialized view. * * @see https://www.postgresql.org/docs/current/sql-creatematerializedview.html */ readonly createMaterializedView: (...args: Parameters<mViews.CreateMaterializedView>) => void; /** * Remove a materialized view. * * @see https://www.postgresql.org/docs/current/sql-dropmaterializedview.html */ readonly dropMaterializedView: (...args: Parameters<mViews.DropMaterializedView>) => void; /** * Change the definition of a materialized view. * * @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html */ readonly alterMaterializedView: (...args: Parameters<mViews.AlterMaterializedView>) => void; /** * Rename a materialized view. * * @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html */ readonly renameMaterializedView: (...args: Parameters<mViews.RenameMaterializedView>) => void; /** * Rename a materialized view column. * * @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html */ readonly renameMaterializedViewColumn: (...args: Parameters<mViews.RenameMaterializedViewColumn>) => void; /** * Replace the contents of a materialized view. * * @see https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html */ readonly refreshMaterializedView: (...args: Parameters<mViews.RefreshMaterializedView>) => void; /** * Define access privileges. * * @see https://www.postgresql.org/docs/current/sql-grant.html */ readonly grantRoles: (...args: Parameters<grants.GrantRoles>) => void; /** * Remove access privileges. * * @see https://www.postgresql.org/docs/current/sql-revoke.html */ readonly revokeRoles: (...args: Parameters<grants.RevokeRoles>) => void; /** * Define access privileges. * * @see https://www.postgresql.org/docs/current/sql-grant.html */ readonly grantOnSchemas: (...args: Parameters<grants.GrantOnSchemas>) => void; /** * Remove access privileges. * * @see https://www.postgresql.org/docs/current/sql-revoke.html */ readonly revokeOnSchemas: (...args: Parameters<grants.RevokeOnSchemas>) => void; /** * Define access privileges. * * @see https://www.postgresql.org/docs/current/sql-grant.html */ readonly grantOnTables: (...args: Parameters<grants.GrantOnTables>) => void; /** * Remove access privileges. * * @see https://www.postgresql.org/docs/current/sql-revoke.html */ readonly revokeOnTables: (...args: Parameters<grants.RevokeOnTables>) => void; /** * Define a new cast. * * @see https://www.postgresql.org/docs/current/sql-createcast.html */ readonly createCast: (...args: Parameters<casts.CreateCast>) => void; /** * Remove a cast. * * @see https://www.postgresql.org/docs/current/sql-dropcast.html */ readonly dropCast: (...args: Parameters<casts.DropCast>) => void; /** * Run raw SQL, with some optional _[very basic](http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/)_ mustache templating. * * This is a low-level operation, and you should use the higher-level operations whenever possible. * * @param sql SQL query to run. * @param args Optional `key/val` of arguments to replace. * * @see https://www.postgresql.org/docs/current/sql-commands.html */ readonly sql: (...args: Parameters<sql.Sql>) => void; /** * Inserts raw string, **which is not escaped**. * * @param sql String to **not escaped**. * * @example * { default: pgm.func('CURRENT_TIMESTAMP') } */ readonly func: (sql: string) => PgLiteral; /** * The `db` client instance. * * Can be used to run queries directly. */ readonly db: DB; private _steps; private _REVERSE_MODE; private _useTransaction; constructor(db: DB, typeShorthands: ColumnDefinitions | undefined, shouldDecamelize: boolean, logger: Logger); /** * Run the reverse of the migration. Useful for creating a new migration that * reverts a previous migration. */ enableReverseMode(): this; /** * By default, all migrations are run in one transaction, but some DB * operations like add type value (`pgm.addTypeValue`) does not work if the * type is not created in the same transaction. * e.g. if it is created in previous migration. You need to run specific * migration outside a transaction (`pgm.noTransaction`). * Be aware that this means that you can have some migrations applied and some * not applied, if there is some error during migrating (leading to `ROLLBACK`). */ noTransaction(): this; isUsingTransaction(): boolean; getSql(): string; getSqlSteps(): string[]; }