New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-pg-migrate

Package Overview
Dependencies
Maintainers
3
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pg-migrate - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

225

CHANGELOG.md
# Change Log
## [3.4.0](2018-06-05)
### Changed
- Constraint name is optional (for backward compatibility) [#268](https://github.com/salsita/node-pg-migrate/pull/268)
- Updated node and service versions [#269](https://github.com/salsita/node-pg-migrate/pull/269)
!!! Minimal supported node version is now 6 !!!
## [3.3.0](2018-05-21)

@@ -7,3 +16,3 @@

* Promisifying client.connect [#265](https://github.com/salsita/node-pg-migrate/pull/265)
- Promisifying client.connect [#265](https://github.com/salsita/node-pg-migrate/pull/265)

@@ -14,3 +23,3 @@ ## [3.2.1](2018-05-21)

* Fix type name issue when the type is not in the default schema [#264](https://github.com/salsita/node-pg-migrate/pull/264)
- Fix type name issue when the type is not in the default schema [#264](https://github.com/salsita/node-pg-migrate/pull/264)

@@ -21,4 +30,4 @@ ## [3.2.0](2018-05-17)

* Add support for opclass option in createIndex [#259](https://github.com/salsita/node-pg-migrate/pull/259)
* Ability to specify extension schema [#260](https://github.com/salsita/node-pg-migrate/pull/260)
- Add support for opclass option in createIndex [#259](https://github.com/salsita/node-pg-migrate/pull/259)
- Ability to specify extension schema [#260](https://github.com/salsita/node-pg-migrate/pull/260)

@@ -29,3 +38,3 @@ ## [3.1.2](2018-05-14)

* Using dollar-quoted strings in comments [#255](https://github.com/salsita/node-pg-migrate/pull/255)
- Using dollar-quoted strings in comments [#255](https://github.com/salsita/node-pg-migrate/pull/255)

@@ -36,3 +45,3 @@ ## [3.1.1](2018-05-02)

* Fixing optional options in create and drop statements [#250](https://github.com/salsita/node-pg-migrate/pull/250)
- Fixing optional options in create and drop statements [#250](https://github.com/salsita/node-pg-migrate/pull/250)

@@ -43,3 +52,3 @@ ## [3.1.0](2018-04-19)

* Handling SQL files [#246](https://github.com/salsita/node-pg-migrate/pull/246)
- Handling SQL files [#246](https://github.com/salsita/node-pg-migrate/pull/246)

@@ -52,4 +61,4 @@ ## [3.0.0](2018-04-12)

* Fix comment not being optional [#244](https://github.com/salsita/node-pg-migrate/pull/244)
* Fix behavior when singleTransaction is not set [#245](https://github.com/salsita/node-pg-migrate/pull/245)
- Fix comment not being optional [#244](https://github.com/salsita/node-pg-migrate/pull/244)
- Fix behavior when singleTransaction is not set [#245](https://github.com/salsita/node-pg-migrate/pull/245)

@@ -60,4 +69,4 @@ ## [3.0.0-rc4](2018-04-03)

* Implement failsafe locking [#239](https://github.com/salsita/node-pg-migrate/pull/239)
* Updated docs about locking [#240](https://github.com/salsita/node-pg-migrate/pull/240)
- Implement failsafe locking [#239](https://github.com/salsita/node-pg-migrate/pull/239)
- Updated docs about locking [#240](https://github.com/salsita/node-pg-migrate/pull/240)

@@ -68,10 +77,10 @@ ## [3.0.0-rc3](2018-04-03)

* Add log option to runner.js [#238](https://github.com/salsita/node-pg-migrate/pull/238)
* Structuring docs [#237](https://github.com/salsita/node-pg-migrate/pull/237)
* Prettier formatting [#236](https://github.com/salsita/node-pg-migrate/pull/236)
* Displaying function name on infer failure [#235](https://github.com/salsita/node-pg-migrate/pull/235)
* Materialized views handling [#234](https://github.com/salsita/node-pg-migrate/pull/234)
* Handling Views [#233](https://github.com/salsita/node-pg-migrate/pull/233)
* Cockroach test [#231](https://github.com/salsita/node-pg-migrate/pull/231)
* Prettier [#230](https://github.com/salsita/node-pg-migrate/pull/230)
- Add log option to runner.js [#238](https://github.com/salsita/node-pg-migrate/pull/238)
- Structuring docs [#237](https://github.com/salsita/node-pg-migrate/pull/237)
- Prettier formatting [#236](https://github.com/salsita/node-pg-migrate/pull/236)
- Displaying function name on infer failure [#235](https://github.com/salsita/node-pg-migrate/pull/235)
- Materialized views handling [#234](https://github.com/salsita/node-pg-migrate/pull/234)
- Handling Views [#233](https://github.com/salsita/node-pg-migrate/pull/233)
- Cockroach test [#231](https://github.com/salsita/node-pg-migrate/pull/231)
- Prettier [#230](https://github.com/salsita/node-pg-migrate/pull/230)

@@ -82,3 +91,3 @@ ## [3.0.0-rc2](2018-03-26)

* Fixing setting comments on columns [#228](https://github.com/salsita/node-pg-migrate/pull/228)
- Fixing setting comments on columns [#228](https://github.com/salsita/node-pg-migrate/pull/228)

@@ -89,3 +98,3 @@ ## [2.26.3](2018-03-26)

* Fixing setting comments on columns [#228](https://github.com/salsita/node-pg-migrate/pull/228)
- Fixing setting comments on columns [#228](https://github.com/salsita/node-pg-migrate/pull/228)

@@ -96,7 +105,7 @@ # [3.0.0-rc](2018-03-23)

* Single transaction as default [#205](https://github.com/salsita/node-pg-migrate/pull/205)
* Versioning type shorthands [#190](https://github.com/salsita/node-pg-migrate/pull/190)
- Single transaction as default [#205](https://github.com/salsita/node-pg-migrate/pull/205)
- Versioning type shorthands [#190](https://github.com/salsita/node-pg-migrate/pull/190)
(type shorthands were moved from global config to migrations scripts)
* Using camel case in API [#189](https://github.com/salsita/node-pg-migrate/pull/189)
* Removed `pg-migrate` script
- Using camel case in API [#189](https://github.com/salsita/node-pg-migrate/pull/189)
- Removed `pg-migrate` script
(use `node-pg-migrate`)

@@ -106,3 +115,3 @@

* Running test migrations on CircleCI [#221](https://github.com/salsita/node-pg-migrate/pull/221)
- Running test migrations on CircleCI [#221](https://github.com/salsita/node-pg-migrate/pull/221)

@@ -113,3 +122,3 @@ ## [2.26.2](2018-03-23)

* Fix runner for zero migrations [#224](https://github.com/salsita/node-pg-migrate/pull/224)
- Fix runner for zero migrations [#224](https://github.com/salsita/node-pg-migrate/pull/224)

@@ -120,4 +129,4 @@ ## [2.26.1](2018-03-23)

* Fixing altering role [#222](https://github.com/salsita/node-pg-migrate/pull/222)
* Fixes from 3.0 [#223](https://github.com/salsita/node-pg-migrate/pull/223)
- Fixing altering role [#222](https://github.com/salsita/node-pg-migrate/pull/222)
- Fixes from 3.0 [#223](https://github.com/salsita/node-pg-migrate/pull/223)

@@ -128,3 +137,3 @@ ## [2.26.0](2018-03-16)

* Support for policies [#219](https://github.com/salsita/node-pg-migrate/pull/219)
- Support for policies [#219](https://github.com/salsita/node-pg-migrate/pull/219)

@@ -135,3 +144,3 @@ ## [2.25.1](2018-03-16)

* Role inherit fix [#218](https://github.com/salsita/node-pg-migrate/pull/218)
- Role inherit fix [#218](https://github.com/salsita/node-pg-migrate/pull/218)

@@ -142,8 +151,8 @@ ## [2.25.0](2018-03-08)

* (No)Transaction handling [#213](https://github.com/salsita/node-pg-migrate/pull/213)
* Parens around INHERITS clause [#214](https://github.com/salsita/node-pg-migrate/pull/214)
- (No)Transaction handling [#213](https://github.com/salsita/node-pg-migrate/pull/213)
- Parens around INHERITS clause [#214](https://github.com/salsita/node-pg-migrate/pull/214)
### Added
* Exposing DB [#212](https://github.com/salsita/node-pg-migrate/pull/212)
- Exposing DB [#212](https://github.com/salsita/node-pg-migrate/pull/212)

@@ -154,3 +163,3 @@ ## [2.24.1](2018-03-05)

* Fix auto create schema [#206](https://github.com/salsita/node-pg-migrate/pull/206)
- Fix auto create schema [#206](https://github.com/salsita/node-pg-migrate/pull/206)

@@ -161,3 +170,3 @@ ## [2.24.0](2018-03-01)

* Add `--single-transaction` option [#204](https://github.com/salsita/node-pg-migrate/pull/204)
- Add `--single-transaction` option [#204](https://github.com/salsita/node-pg-migrate/pull/204)

@@ -168,3 +177,3 @@ ## [2.23.1](2018-02-21)

* Correct handling of multiline constraints [#202](https://github.com/salsita/node-pg-migrate/pull/202)
- Correct handling of multiline constraints [#202](https://github.com/salsita/node-pg-migrate/pull/202)

@@ -175,5 +184,5 @@ ## [2.23.0](2018-02-20)

* Updating deps, removing vulnerablity status for peer and optional dependencies [#199](https://github.com/salsita/node-pg-migrate/pull/199)
* Removing regex [#198](https://github.com/salsita/node-pg-migrate/pull/198)
* Adding ability to specify database name with 'database' option [#197](https://github.com/salsita/node-pg-migrate/pull/197)
- Updating deps, removing vulnerablity status for peer and optional dependencies [#199](https://github.com/salsita/node-pg-migrate/pull/199)
- Removing regex [#198](https://github.com/salsita/node-pg-migrate/pull/198)
- Adding ability to specify database name with 'database' option [#197](https://github.com/salsita/node-pg-migrate/pull/197)

@@ -184,4 +193,4 @@ ## [2.22.2](2018-02-20)

* Role encrypted default [#196](https://github.com/salsita/node-pg-migrate/pull/196)
* Running queries in order [#195](https://github.com/salsita/node-pg-migrate/pull/195)
- Role encrypted default [#196](https://github.com/salsita/node-pg-migrate/pull/196)
- Running queries in order [#195](https://github.com/salsita/node-pg-migrate/pull/195)

@@ -192,3 +201,3 @@ ## [2.22.1](2018-02-20)

* Passing props [#194](https://github.com/salsita/node-pg-migrate/pull/194)
- Passing props [#194](https://github.com/salsita/node-pg-migrate/pull/194)

@@ -199,5 +208,5 @@ ## [2.22.0](2018-02-20)

* Auto create configured schemas if they don't exist [#192](https://github.com/salsita/node-pg-migrate/pull/192)
* Add ifNotExists option to create extension [#188](https://github.com/salsita/node-pg-migrate/pull/188)
* Programmatic API docs [#187](https://github.com/salsita/node-pg-migrate/pull/187)
- Auto create configured schemas if they don't exist [#192](https://github.com/salsita/node-pg-migrate/pull/192)
- Add ifNotExists option to create extension [#188](https://github.com/salsita/node-pg-migrate/pull/188)
- Programmatic API docs [#187](https://github.com/salsita/node-pg-migrate/pull/187)

@@ -208,3 +217,3 @@ ## [2.21.0](2018-02-12)

* Table and column comments [#183](https://github.com/salsita/node-pg-migrate/pull/183)
- Table and column comments [#183](https://github.com/salsita/node-pg-migrate/pull/183)

@@ -215,4 +224,4 @@ ## [2.19.0](2018-02-06)

* `migration-file-language` can be set in config file [#180](https://github.com/salsita/node-pg-migrate/pull/180)
* Treat number argument to up/down migration as timestamp [#179](https://github.com/salsita/node-pg-migrate/pull/179)
- `migration-file-language` can be set in config file [#180](https://github.com/salsita/node-pg-migrate/pull/180)
- Treat number argument to up/down migration as timestamp [#179](https://github.com/salsita/node-pg-migrate/pull/179)

@@ -223,3 +232,3 @@ ## [2.18.1](2018-02-06)

* Fixing addConstraint method with object expression [#176](https://github.com/salsita/node-pg-migrate/pull/176)
- Fixing addConstraint method with object expression [#176](https://github.com/salsita/node-pg-migrate/pull/176)

@@ -230,10 +239,10 @@ ## [2.18.0](2018-02-05)

* Add no lock option [#171](https://github.com/salsita/node-pg-migrate/pull/171)
* Updated docs [#174](https://github.com/salsita/node-pg-migrate/pull/174)
- Add no lock option [#171](https://github.com/salsita/node-pg-migrate/pull/171)
- Updated docs [#174](https://github.com/salsita/node-pg-migrate/pull/174)
### Changed
* Remove old version number from index.d.ts [#173](https://github.com/salsita/node-pg-migrate/pull/173)
* Remove default match in column reference [#172](https://github.com/salsita/node-pg-migrate/pull/172)
* Refactor code to use camel casing [#167](https://github.com/salsita/node-pg-migrate/pull/167)
- Remove old version number from index.d.ts [#173](https://github.com/salsita/node-pg-migrate/pull/173)
- Remove default match in column reference [#172](https://github.com/salsita/node-pg-migrate/pull/172)
- Refactor code to use camel casing [#167](https://github.com/salsita/node-pg-migrate/pull/167)

@@ -244,4 +253,4 @@ ## [2.17.0](2018-01-26)

* Added typescript migration template [#165](https://github.com/salsita/node-pg-migrate/pull/165)
* Updated type definitions to accept db client config [#166](https://github.com/salsita/node-pg-migrate/pull/166)
- Added typescript migration template [#165](https://github.com/salsita/node-pg-migrate/pull/165)
- Updated type definitions to accept db client config [#166](https://github.com/salsita/node-pg-migrate/pull/166)

@@ -252,3 +261,3 @@ ## [2.16.2](2018-01-25)

* Deleted duplicate declaration [#164](https://github.com/salsita/node-pg-migrate/pull/164)
- Deleted duplicate declaration [#164](https://github.com/salsita/node-pg-migrate/pull/164)

@@ -259,7 +268,7 @@ ## [2.16.1](2018-01-25)

* Updated dependencies [#158](https://github.com/salsita/node-pg-migrate/pull/158)
- Updated dependencies [#158](https://github.com/salsita/node-pg-migrate/pull/158)
### Fixed
* Typescript definition fixes [#162](https://github.com/salsita/node-pg-migrate/pull/162)
- Typescript definition fixes [#162](https://github.com/salsita/node-pg-migrate/pull/162)

@@ -270,6 +279,6 @@ ## [2.16.0](2018-01-23)

* Uniting drop statements [#154](https://github.com/salsita/node-pg-migrate/pull/154)
* Handling domains [#155](https://github.com/salsita/node-pg-migrate/pull/155)
* Operator operations [#156](https://github.com/salsita/node-pg-migrate/pull/156)
* Sequences operations [#157](https://github.com/salsita/node-pg-migrate/pull/157)
- Uniting drop statements [#154](https://github.com/salsita/node-pg-migrate/pull/154)
- Handling domains [#155](https://github.com/salsita/node-pg-migrate/pull/155)
- Operator operations [#156](https://github.com/salsita/node-pg-migrate/pull/156)
- Sequences operations [#157](https://github.com/salsita/node-pg-migrate/pull/157)

@@ -280,7 +289,7 @@ ## [2.15.0](2018-01-11)

* Handle rejections in migration actions [#148](https://github.com/salsita/node-pg-migrate/pull/148)
- Handle rejections in migration actions [#148](https://github.com/salsita/node-pg-migrate/pull/148)
### Added
* TypeScript declaration file [#147](https://github.com/salsita/node-pg-migrate/pull/147) [#150](https://github.com/salsita/node-pg-migrate/pull/150)
- TypeScript declaration file [#147](https://github.com/salsita/node-pg-migrate/pull/147) [#150](https://github.com/salsita/node-pg-migrate/pull/150)

@@ -291,8 +300,8 @@ ## [2.14.0](2017-11-14)

* Deferrable column constraints [#139](https://github.com/salsita/node-pg-migrate/pull/139)
* Possibility to use function in multi-column index [#140](https://github.com/salsita/node-pg-migrate/pull/140)
- Deferrable column constraints [#139](https://github.com/salsita/node-pg-migrate/pull/139)
- Possibility to use function in multi-column index [#140](https://github.com/salsita/node-pg-migrate/pull/140)
### Changed
* Changed all references from pg-migrate to node-pg-migrate [#141](https://github.com/salsita/node-pg-migrate/pull/141)
- Changed all references from pg-migrate to node-pg-migrate [#141](https://github.com/salsita/node-pg-migrate/pull/141)

@@ -305,4 +314,4 @@ !!! Breaking change from version 3 !!! (now with warning)

* Cannot use embedded value in config [#137](https://github.com/salsita/node-pg-migrate/pull/137)
* add space before `USING` keyword [#138](https://github.com/salsita/node-pg-migrate/pull/138)
- Cannot use embedded value in config [#137](https://github.com/salsita/node-pg-migrate/pull/137)
- add space before `USING` keyword [#138](https://github.com/salsita/node-pg-migrate/pull/138)

@@ -313,3 +322,3 @@ ## [2.13.1](2017-10-23)

* addTypeValue's `after` option is using BEFORE instead of AFTER [#133](https://github.com/salsita/node-pg-migrate/pull/133)
- addTypeValue's `after` option is using BEFORE instead of AFTER [#133](https://github.com/salsita/node-pg-migrate/pull/133)

@@ -320,3 +329,3 @@ ## [2.13.0](2017-10-12)

* Ability to specify files to ignore in migrations directory [#131](https://github.com/salsita/node-pg-migrate/pull/131)
- Ability to specify files to ignore in migrations directory [#131](https://github.com/salsita/node-pg-migrate/pull/131)

@@ -327,10 +336,10 @@ ## [2.12.0](2017-10-09)

* Dollar quoted string constants [#127](https://github.com/salsita/node-pg-migrate/pull/127)
* Table unique constraint can be array of arrays [#126](https://github.com/salsita/node-pg-migrate/pull/126)
- Dollar quoted string constants [#127](https://github.com/salsita/node-pg-migrate/pull/127)
- Table unique constraint can be array of arrays [#126](https://github.com/salsita/node-pg-migrate/pull/126)
### Changed
* If user disables migration, return Error instead of string [#125](https://github.com/salsita/node-pg-migrate/pull/125)
* Circle CI integration [#124](https://github.com/salsita/node-pg-migrate/pull/124)
* Moved to Salsita organization [#122](https://github.com/salsita/node-pg-migrate/pull/122)
- If user disables migration, return Error instead of string [#125](https://github.com/salsita/node-pg-migrate/pull/125)
- Circle CI integration [#124](https://github.com/salsita/node-pg-migrate/pull/124)
- Moved to Salsita organization [#122](https://github.com/salsita/node-pg-migrate/pull/122)

@@ -341,3 +350,3 @@ ## [2.11.1](2017-09-26)

* Fixed SQL for dropping multiple columns [#120](https://github.com/salsita/node-pg-migrate/pull/120)
- Fixed SQL for dropping multiple columns [#120](https://github.com/salsita/node-pg-migrate/pull/120)

@@ -348,3 +357,3 @@ ## [2.11.0](2017-09-25)

* Schemas operations [#119](https://github.com/salsita/node-pg-migrate/pull/119)
- Schemas operations [#119](https://github.com/salsita/node-pg-migrate/pull/119)

@@ -355,3 +364,3 @@ ## [2.10.1](2017-09-25)

* Fixed invalid SQL for table level foreign key [#118](https://github.com/salsita/node-pg-migrate/pull/118)
- Fixed invalid SQL for table level foreign key [#118](https://github.com/salsita/node-pg-migrate/pull/118)

@@ -362,3 +371,3 @@ ## [2.10.0](2017-09-21)

* Ability to specify constraints on table level [#114](https://github.com/salsita/node-pg-migrate/pull/114)
- Ability to specify constraints on table level [#114](https://github.com/salsita/node-pg-migrate/pull/114)

@@ -369,4 +378,4 @@ ## [2.9.0](2017-09-12)

* Alter type functions [#111](https://github.com/salsita/node-pg-migrate/pull/111)
* redo command [#112](https://github.com/salsita/node-pg-migrate/pull/112)
- Alter type functions [#111](https://github.com/salsita/node-pg-migrate/pull/111)
- redo command [#112](https://github.com/salsita/node-pg-migrate/pull/112)

@@ -377,3 +386,3 @@ ## [2.8.2](2017-09-11)

* Fix automatic reversal of addColumns [#110](https://github.com/salsita/node-pg-migrate/pull/110)
- Fix automatic reversal of addColumns [#110](https://github.com/salsita/node-pg-migrate/pull/110)

@@ -384,7 +393,7 @@ ## [2.8.1](2017-09-06)

* Fixing referencing column [#107](https://github.com/salsita/node-pg-migrate/pull/107)
- Fixing referencing column [#107](https://github.com/salsita/node-pg-migrate/pull/107)
### Changed
* Formatting changes, added licence [#108](https://github.com/salsita/node-pg-migrate/pull/108)
- Formatting changes, added licence [#108](https://github.com/salsita/node-pg-migrate/pull/108)

@@ -395,3 +404,3 @@ ## [2.8.0](2017-09-04)

* Trigger operations [#104](https://github.com/salsita/node-pg-migrate/pull/104)
- Trigger operations [#104](https://github.com/salsita/node-pg-migrate/pull/104)

@@ -402,3 +411,3 @@ ## [2.7.1](2017-08-28)

* Support object with schema and table name in more places [#105](https://github.com/salsita/node-pg-migrate/pull/105)
- Support object with schema and table name in more places [#105](https://github.com/salsita/node-pg-migrate/pull/105)

@@ -409,3 +418,3 @@ ## [2.7.0](2017-08-01)

* Function operations [#103](https://github.com/salsita/node-pg-migrate/pull/103)
- Function operations [#103](https://github.com/salsita/node-pg-migrate/pull/103)

@@ -416,4 +425,4 @@ ## [2.6.0](2017-07-20)

* Support for pg >=4.3.0 <8.0.0
* Interpret only files as migrations in migration directory [#101](https://github.com/salsita/node-pg-migrate/pull/101)
- Support for pg >=4.3.0 <8.0.0
- Interpret only files as migrations in migration directory [#101](https://github.com/salsita/node-pg-migrate/pull/101)

@@ -424,4 +433,4 @@ ## [2.5.0](2017-07-19)

* USING clause in alter column [#99](https://github.com/salsita/node-pg-migrate/pull/99)
* Role operations [#100](https://github.com/salsita/node-pg-migrate/pull/100)
- USING clause in alter column [#99](https://github.com/salsita/node-pg-migrate/pull/99)
- Role operations [#100](https://github.com/salsita/node-pg-migrate/pull/100)

@@ -432,3 +441,3 @@ ## [2.4.0](2017-07-17)

* Do not check file extension of migration file [#93](https://github.com/salsita/node-pg-migrate/pull/93)
- Do not check file extension of migration file [#93](https://github.com/salsita/node-pg-migrate/pull/93)

@@ -439,3 +448,3 @@ ## [2.3.0](2017-06-20)

* JSON config and type shorthands [see](README.md#json-configuration) [#91](https://github.com/salsita/node-pg-migrate/pull/91)
- JSON config and type shorthands [see](README.md#json-configuration) [#91](https://github.com/salsita/node-pg-migrate/pull/91)

@@ -446,3 +455,3 @@ ## [2.2.1](2017-05-26)

* Syntax error in node 4
- Syntax error in node 4

@@ -453,5 +462,5 @@ ## [2.2.0](2017-05-25)

* Better error logging [#86](https://github.com/salsita/node-pg-migrate/pull/86)
* Locking migrations [#88](https://github.com/salsita/node-pg-migrate/pull/88)
* Updated docs [#89](https://github.com/salsita/node-pg-migrate/pull/89)
- Better error logging [#86](https://github.com/salsita/node-pg-migrate/pull/86)
- Locking migrations [#88](https://github.com/salsita/node-pg-migrate/pull/88)
- Updated docs [#89](https://github.com/salsita/node-pg-migrate/pull/89)

@@ -462,3 +471,3 @@ ## [2.1.1](2017-05-18)

* Down migration when down method is inferred [#84](https://github.com/salsita/node-pg-migrate/pull/84)
- Down migration when down method is inferred [#84](https://github.com/salsita/node-pg-migrate/pull/84)

@@ -469,3 +478,3 @@ ## [2.1.0](2017-05-10)

* Enable string functions and arrays as default column values [#82](https://github.com/salsita/node-pg-migrate/pull/82)
- Enable string functions and arrays as default column values [#82](https://github.com/salsita/node-pg-migrate/pull/82)

@@ -478,10 +487,10 @@ ## [2.0.0](2017-04-28)

* supports only node >= 4
* `check-order` flag now defaults to `true` (to switch it off supply `--no-check-order` on command line)
* [dotenv](https://www.npmjs.com/package/dotenv) package is `optionalDependency`
* `s` option is now alias for `schema` which sets schema for migrations SQL, if you only need to change schema of migrations table use `--migrations-schema`
- supports only node >= 4
- `check-order` flag now defaults to `true` (to switch it off supply `--no-check-order` on command line)
- [dotenv](https://www.npmjs.com/package/dotenv) package is `optionalDependency`
- `s` option is now alias for `schema` which sets schema for migrations SQL, if you only need to change schema of migrations table use `--migrations-schema`
### Added
* [config](https://www.npmjs.com/package/config) package as `optionalDependency`
* Migration can return `Promise`
- [config](https://www.npmjs.com/package/config) package as `optionalDependency`
- Migration can return `Promise`

@@ -16,42 +16,29 @@ "use strict";

exports.default = function (connectionString) {
var log = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : console.error;
exports.default = (connectionString, log = console.error) => {
const client = new _pg2.default.Client(connectionString);
let clientActive = false;
const beforeCloseListeners = [];
var client = new _pg2.default.Client(connectionString);
var clientActive = false;
var beforeCloseListeners = [];
var createConnection = function createConnection() {
return new Promise(function (resolve, reject) {
return clientActive ? resolve() : client.connect(function (err) {
if (err) {
log("could not connect to postgres", err);
return reject(err);
}
clientActive = true;
return resolve();
});
});
};
var query = function query() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
const createConnection = () => new Promise((resolve, reject) => clientActive ? resolve() : client.connect(err => {
if (err) {
log("could not connect to postgres", err);
return reject(err);
}
clientActive = true;
return resolve();
}));
return createConnection().then(function () {
return client.query.apply(client, args);
}).catch(function (err) {
var message = err.message,
const query = (...args) => createConnection().then(() => client.query(...args)).catch(err => {
const message = err.message,
position = err.position;
var string = args[0].text || args[0];
if (message && position >= 1) {
var endLineWrapIndexOf = string.indexOf("\n", position);
var endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length;
var stringStart = string.substring(0, endLineWrapPos);
var stringEnd = string.substr(endLineWrapPos);
var startLineWrapPos = stringStart.lastIndexOf("\n") + 1;
var padding = " ".repeat(position - startLineWrapPos - 1);
log(`Error executing:
const string = args[0].text || args[0];
if (message && position >= 1) {
const endLineWrapIndexOf = string.indexOf("\n", position);
const endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length;
const stringStart = string.substring(0, endLineWrapPos);
const stringEnd = string.substr(endLineWrapPos);
const startLineWrapPos = stringStart.lastIndexOf("\n") + 1;
const padding = " ".repeat(position - startLineWrapPos - 1);
log(`Error executing:
${stringStart}

@@ -62,24 +49,13 @@ ${padding}^^^^${stringEnd}

`);
} else {
log(`Error executing:
} else {
log(`Error executing:
${string}
${err}
`);
}
throw err;
});
};
}
throw err;
});
var select = function select(string) {
return query(string).then(function (result) {
return result && result.rows;
});
};
var column = function column(string, columnName) {
return select(string).then(function (rows) {
return rows.map(function (r) {
return r[columnName];
});
});
};
const select = string => query(string).then(result => result && result.rows);
const column = (string, columnName) => select(string).then(rows => rows.map(r => r[columnName]));

@@ -91,18 +67,10 @@ return {

addBeforeCloseListener: function addBeforeCloseListener(listener) {
return beforeCloseListeners.push(listener);
},
addBeforeCloseListener: listener => beforeCloseListeners.push(listener),
close: function close() {
return beforeCloseListeners.reduce(function (promise, listener) {
return promise.then(listener).catch(function (err) {
return log(err.stack || err);
});
}, Promise.resolve()).then(function () {
clientActive = false;
if (client) {
client.end();
}
});
}
close: () => beforeCloseListeners.reduce((promise, listener) => promise.then(listener).catch(err => log(err.stack || err)), Promise.resolve()).then(() => {
clientActive = false;
if (client) {
client.end();
}
})
};

@@ -109,0 +77,0 @@ }; /*

@@ -7,13 +7,2 @@ "use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*
The migration builder is used to actually create a migration from instructions
A new instance of MigrationBuilder is instantiated and passed to the up or down block
of each migration when it is being run.
It makes the methods available via the pgm variable and stores up the sql commands.
This is what makes it possible to do this without making everything async
and it makes inference of down migrations possible.
*/
var _utils = require("./utils");

@@ -83,11 +72,16 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/* eslint-disable security/detect-non-literal-fs-filename */
var MigrationBuilder = function () {
function MigrationBuilder(typeShorthands, db) {
var _this = this;
/*
The migration builder is used to actually create a migration from instructions
_classCallCheck(this, MigrationBuilder);
A new instance of MigrationBuilder is instantiated and passed to the up or down block
of each migration when it is being run.
It makes the methods available via the pgm variable and stores up the sql commands.
This is what makes it possible to do this without making everything async
and it makes inference of down migrations possible.
*/
class MigrationBuilder {
constructor(typeShorthands, db) {
this._steps = [];

@@ -101,10 +95,8 @@ this._REVERSE_MODE = false;

// to the steps array
var wrap = function wrap(operation) {
return function () {
if (_this._REVERSE_MODE && typeof operation.reverse !== "function") {
var name = `pgm.${operation.name}()`;
throw new Error(`Impossible to automatically infer down migration for "${name}"`);
}
_this._steps = _this._steps.concat(_this._REVERSE_MODE ? operation.reverse.apply(operation, arguments) : operation.apply(undefined, arguments));
};
const wrap = operation => (...args) => {
if (this._REVERSE_MODE && typeof operation.reverse !== "function") {
const name = `pgm.${operation.name}()`;
throw new Error(`Impossible to automatically infer down migration for "${name}"`);
}
this._steps = this._steps.concat(this._REVERSE_MODE ? operation.reverse(...args) : operation(...args));
};

@@ -213,9 +205,7 @@

// expose DB so we can access database within transaction
var wrapDB = function wrapDB(operation) {
return function () {
if (_this._REVERSE_MODE) {
throw new Error("Impossible to automatically infer down migration");
}
return operation.apply(undefined, arguments);
};
const wrapDB = operation => (...args) => {
if (this._REVERSE_MODE) {
throw new Error("Impossible to automatically infer down migration");
}
return operation(...args);
};

@@ -228,37 +218,25 @@ this.db = {

_createClass(MigrationBuilder, [{
key: "enableReverseMode",
value: function enableReverseMode() {
this._REVERSE_MODE = true;
return this;
}
}, {
key: "noTransaction",
value: function noTransaction() {
this._use_transaction = false;
return this;
}
}, {
key: "isUsingTransaction",
value: function isUsingTransaction() {
return this._use_transaction;
}
}, {
key: "getSql",
value: function getSql() {
return `${this.getSqlSteps().join("\n")}\n`;
}
}, {
key: "getSqlSteps",
value: function getSqlSteps() {
// in reverse mode, we flip the order of the statements
return this._REVERSE_MODE ? this._steps.slice().reverse() : this._steps;
}
}]);
enableReverseMode() {
this._REVERSE_MODE = true;
return this;
}
return MigrationBuilder;
}();
/* eslint-enable security/detect-non-literal-fs-filename */
noTransaction() {
this._use_transaction = false;
return this;
}
isUsingTransaction() {
return this._use_transaction;
}
exports.default = MigrationBuilder;
getSql() {
return `${this.getSqlSteps().join("\n")}\n`;
}
getSqlSteps() {
// in reverse mode, we flip the order of the statements
return this._REVERSE_MODE ? this._steps.slice().reverse() : this._steps;
}
}
exports.default = MigrationBuilder; /* eslint-enable security/detect-non-literal-fs-filename */

@@ -7,10 +7,2 @@ "use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*
A new Migration is instantiated for each migration file.
It is responsible for storing the name of the file and knowing how to execute
the up and down migrations defined in the file.
*/
var _fs = require("fs");

@@ -36,37 +28,29 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
const SEPARATOR = "_"; /*
A new Migration is instantiated for each migration file.
It is responsible for storing the name of the file and knowing how to execute
the up and down migrations defined in the file.
*/
var SEPARATOR = "_";
class Migration {
// class method that creates a new migration file by cloning the migration template
static create(name, directory, language) {
// ensure the migrations directory exists
_mkdirp2.default.sync(directory);
var Migration = function () {
_createClass(Migration, null, [{
key: "create",
// file name looks like migrations/1391877300255_migration-title.js
const newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${language}`;
// class method that creates a new migration file by cloning the migration template
value: function create(name, directory, language) {
// ensure the migrations directory exists
_mkdirp2.default.sync(directory);
// copy the default migration template to the new file location
// eslint-disable-next-line security/detect-non-literal-fs-filename
_fs2.default.createReadStream(_path2.default.resolve(__dirname, `./migration-template.${language}`)
// eslint-disable-next-line security/detect-non-literal-fs-filename
).pipe(_fs2.default.createWriteStream(newFile));
// file name looks like migrations/1391877300255_migration-title.js
var newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${language}`;
return new Migration(newFile, directory);
}
// copy the default migration template to the new file location
_fs2.default // eslint-disable-line security/detect-non-literal-fs-filename
.createReadStream(_path2.default.resolve(__dirname, `./migration-template.${language}`)).pipe(_fs2.default.createWriteStream(newFile)); // eslint-disable-line security/detect-non-literal-fs-filename
return new Migration(newFile, directory);
}
}]);
function Migration(db, migrationPath) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
up = _ref.up,
down = _ref.down;
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var typeShorthands = arguments[4];
var log = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : console.log;
_classCallCheck(this, Migration);
constructor(db, migrationPath, { up, down } = {}, options = {}, typeShorthands, log = console.log) {
this.db = db;

@@ -83,88 +67,75 @@ this.path = migrationPath;

_createClass(Migration, [{
key: "_apply",
value: function _apply(action, pgm) {
var _this = this;
return new Promise(function (resolve, reject) {
if (action.length === 2) {
action(pgm, resolve);
_apply(action, pgm) {
return new Promise((resolve, reject) => {
if (action.length === 2) {
action(pgm, resolve);
} else {
const result = action(pgm);
// result conforms to Promises/A+ spec
if (result && typeof result === "object" && typeof result.then === "function") {
result.then(resolve).catch(reject);
} else {
var result = action(pgm);
// result conforms to Promises/A+ spec
if (result && typeof result === "object" && typeof result.then === "function") {
result.then(resolve).catch(reject);
} else {
resolve();
}
resolve();
}
}).then(function () {
var sqlSteps = pgm.getSqlSteps();
}
}).then(() => {
const sqlSteps = pgm.getSqlSteps();
var schema = (0, _utils.getMigrationTableSchema)(_this.options);
var migrationsTable = _this.options.migrationsTable;
var name = _this.name;
const schema = (0, _utils.getMigrationTableSchema)(this.options);
const migrationsTable = this.options.migrationsTable;
const name = this.name;
switch (action) {
case _this.down:
_this.log(`### MIGRATION ${_this.name} (DOWN) ###`);
sqlSteps.push(`DELETE FROM "${schema}"."${migrationsTable}" WHERE name='${name}';`);
break;
case _this.up:
_this.log(`### MIGRATION ${_this.name} (UP) ###`);
sqlSteps.push(`INSERT INTO "${schema}"."${migrationsTable}" (name, run_on) VALUES ('${name}', NOW());`);
break;
default:
throw new Error("Unknown direction");
}
switch (action) {
case this.down:
this.log(`### MIGRATION ${this.name} (DOWN) ###`);
sqlSteps.push(`DELETE FROM "${schema}"."${migrationsTable}" WHERE name='${name}';`);
break;
case this.up:
this.log(`### MIGRATION ${this.name} (UP) ###`);
sqlSteps.push(`INSERT INTO "${schema}"."${migrationsTable}" (name, run_on) VALUES ('${name}', NOW());`);
break;
default:
throw new Error("Unknown direction");
}
if (!_this.options.singleTransaction && pgm.isUsingTransaction()) {
// if not in singleTransaction mode we need to create our own transaction
sqlSteps.unshift("BEGIN;");
sqlSteps.push("COMMIT;");
} else if (_this.options.singleTransaction && !pgm.isUsingTransaction()) {
// in singleTransaction mode we are already wrapped in a global transaction
_this.log("#> WARNING: Need to break single transaction! <");
sqlSteps.unshift("COMMIT;");
sqlSteps.push("BEGIN;");
} else if (!_this.options.singleTransaction || !pgm.isUsingTransaction()) {
_this.log("#> WARNING: This migration is not wrapped in a transaction! <");
}
if (!this.options.singleTransaction && pgm.isUsingTransaction()) {
// if not in singleTransaction mode we need to create our own transaction
sqlSteps.unshift("BEGIN;");
sqlSteps.push("COMMIT;");
} else if (this.options.singleTransaction && !pgm.isUsingTransaction()) {
// in singleTransaction mode we are already wrapped in a global transaction
this.log("#> WARNING: Need to break single transaction! <");
sqlSteps.unshift("COMMIT;");
sqlSteps.push("BEGIN;");
} else if (!this.options.singleTransaction || !pgm.isUsingTransaction()) {
this.log("#> WARNING: This migration is not wrapped in a transaction! <");
}
_this.log(`${sqlSteps.join("\n")}\n\n`);
this.log(`${sqlSteps.join("\n")}\n\n`);
return sqlSteps.reduce(function (promise, sql) {
return promise.then(function () {
return _this.options.dryRun || _this.db.query(sql);
});
}, Promise.resolve());
});
}
}, {
key: "applyUp",
value: function applyUp() {
var pgm = new _migrationBuilder2.default(this.typeShorthands, this.db);
return sqlSteps.reduce((promise, sql) => promise.then(() => this.options.dryRun || this.db.query(sql)), Promise.resolve());
});
}
return this._apply(this.up, pgm);
}
}, {
key: "applyDown",
value: function applyDown() {
var pgm = new _migrationBuilder2.default(this.typeShorthands, this.db);
applyUp() {
const pgm = new _migrationBuilder2.default(this.typeShorthands, this.db);
if (this.down === false) {
return Promise.reject(new Error(`User has disabled down migration on file: ${this.name}`));
} else if (this.down === undefined) {
// automatically infer the down migration by running the up migration in reverse mode...
pgm.enableReverseMode();
this.down = this.up;
}
return this._apply(this.up, pgm);
}
return this._apply(this.down, pgm);
applyDown() {
const pgm = new _migrationBuilder2.default(this.typeShorthands, this.db);
if (this.down === false) {
return Promise.reject(new Error(`User has disabled down migration on file: ${this.name}`));
} else if (this.down === undefined) {
// automatically infer the down migration by running the up migration in reverse mode...
pgm.enableReverseMode();
this.down = this.up;
}
}]);
return Migration;
}();
return this._apply(this.down, pgm);
}
}
exports.default = Migration;

@@ -10,22 +10,17 @@ "use strict";

var dropDomain = exports.dropDomain = function dropDomain(domainName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropDomain = exports.dropDomain = (domainName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP DOMAIN${ifExistsStr} "${domainName}"${cascadeStr};`;
};
var createDomain = exports.createDomain = function createDomain(typeShorthands) {
var _create = function _create(domainName, type) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var defaultValue = options.default,
collation = options.collation,
notNull = options.notNull,
check = options.check,
constraintName = options.constraintName;
const createDomain = exports.createDomain = typeShorthands => {
const _create = (domainName, type, options = {}) => {
const defaultValue = options.default,
collation = options.collation,
notNull = options.notNull,
check = options.check,
constraintName = options.constraintName;
var constraints = [];
const constraints = [];
if (collation) {

@@ -50,22 +45,20 @@ constraints.push(`COLLATE ${collation}`);

var constraintsStr = constraints.length ? ` ${constraints.join(" ")}` : "";
const constraintsStr = constraints.length ? ` ${constraints.join(" ")}` : "";
var typeStr = (0, _utils.applyType)(type, typeShorthands).type;
const typeStr = (0, _utils.applyType)(type, typeShorthands).type;
return _utils.template`CREATE DOMAIN "${domainName}" AS ${typeStr}${constraintsStr};`;
};
_create.reverse = function (domainName, type, options) {
return dropDomain(domainName, options);
};
_create.reverse = (domainName, type, options) => dropDomain(domainName, options);
return _create;
};
var alterDomain = exports.alterDomain = function alterDomain(domainName, options) {
var defaultValue = options.default,
notNull = options.notNull,
allowNull = options.allowNull,
check = options.check,
constraintName = options.constraintName;
const alterDomain = exports.alterDomain = (domainName, options) => {
const defaultValue = options.default,
notNull = options.notNull,
allowNull = options.allowNull,
check = options.check,
constraintName = options.constraintName;
var actions = [];
const actions = [];
if (defaultValue === null) {

@@ -85,15 +78,9 @@ actions.push("DROP DEFAULT");

return `${actions.map(function (action) {
return _utils.template`ALTER DOMAIN "${domainName}" ${action}`;
}).join(";\n")};`;
return `${actions.map(action => _utils.template`ALTER DOMAIN "${domainName}" ${action}`).join(";\n")};`;
};
var renameDomain = exports.renameDomain = function renameDomain(domainName, newDomainName) {
return _utils.template`ALTER DOMAIN "${domainName}" RENAME TO "${newDomainName}";`;
};
const renameDomain = exports.renameDomain = (domainName, newDomainName) => _utils.template`ALTER DOMAIN "${domainName}" RENAME TO "${newDomainName}";`;
var undoRename = function undoRename(domainName, newDomainName) {
return renameDomain(newDomainName, domainName);
};
const undoRename = (domainName, newDomainName) => renameDomain(newDomainName, domainName);
renameDomain.reverse = undoRename;

@@ -16,22 +16,10 @@ "use strict";

var createExtension = exports.createExtension = function createExtension(extensions) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifNotExists = _ref.ifNotExists,
schema = _ref.schema;
const createExtension = exports.createExtension = (extensions, { ifNotExists, schema } = {}) => {
if (!_lodash2.default.isArray(extensions)) extensions = [extensions]; // eslint-disable-line no-param-reassign
return _lodash2.default.map(extensions, function (extension) {
return _utils.template`CREATE EXTENSION${ifNotExists ? " IF NOT EXISTS" : ""} "${extension}"${schema ? ` SCHEMA "${schema}"` : ""};`;
});
return _lodash2.default.map(extensions, extension => _utils.template`CREATE EXTENSION${ifNotExists ? " IF NOT EXISTS" : ""} "${extension}"${schema ? ` SCHEMA "${schema}"` : ""};`);
};
var dropExtension = exports.dropExtension = function dropExtension(extensions) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref2.ifExists,
cascade = _ref2.cascade;
const dropExtension = exports.dropExtension = (extensions, { ifExists, cascade } = {}) => {
if (!_lodash2.default.isArray(extensions)) extensions = [extensions]; // eslint-disable-line no-param-reassign
return _lodash2.default.map(extensions, function (extension) {
return _utils.template`DROP EXTENSION${ifExists ? " IF EXISTS" : ""} "${extension}"${cascade ? " CASCADE" : ""};`;
});
return _lodash2.default.map(extensions, extension => _utils.template`DROP EXTENSION${ifExists ? " IF EXISTS" : ""} "${extension}"${cascade ? " CASCADE" : ""};`);
};

@@ -38,0 +26,0 @@

@@ -10,34 +10,23 @@ "use strict";

var dropFunction = exports.dropFunction = function dropFunction(typeShorthands) {
return function (functionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
var paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);
return _utils.template`DROP FUNCTION${ifExistsStr} "${functionName}"${paramsStr}${cascadeStr};`;
};
const dropFunction = exports.dropFunction = typeShorthands => (functionName, functionParams = [], { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
const paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);
return _utils.template`DROP FUNCTION${ifExistsStr} "${functionName}"${paramsStr}${cascadeStr};`;
};
var createFunction = exports.createFunction = function createFunction(typeShorthands) {
var _create = function _create(functionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var functionOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
var replace = functionOptions.replace,
_functionOptions$retu = functionOptions.returns,
returns = _functionOptions$retu === undefined ? "void" : _functionOptions$retu,
language = functionOptions.language,
window = functionOptions.window,
_functionOptions$beha = functionOptions.behavior,
behavior = _functionOptions$beha === undefined ? "VOLATILE" : _functionOptions$beha,
onNull = functionOptions.onNull,
_functionOptions$para = functionOptions.parallel,
parallel = _functionOptions$para === undefined ? "UNSAFE" : _functionOptions$para;
const createFunction = exports.createFunction = typeShorthands => {
const _create = (functionName, functionParams = [], functionOptions = {}, definition) => {
const replace = functionOptions.replace;
var _functionOptions$retu = functionOptions.returns;
const returns = _functionOptions$retu === undefined ? "void" : _functionOptions$retu,
language = functionOptions.language,
window = functionOptions.window;
var _functionOptions$beha = functionOptions.behavior;
const behavior = _functionOptions$beha === undefined ? "VOLATILE" : _functionOptions$beha,
onNull = functionOptions.onNull;
var _functionOptions$para = functionOptions.parallel;
const parallel = _functionOptions$para === undefined ? "UNSAFE" : _functionOptions$para;
var options = [];
const options = [];
if (behavior) {

@@ -61,4 +50,4 @@ options.push(behavior);

var replaceStr = replace ? " OR REPLACE" : "";
var paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);
const replaceStr = replace ? " OR REPLACE" : "";
const paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);

@@ -76,16 +65,11 @@ return _utils.template`CREATE${replaceStr} FUNCTION "${functionName}"${paramsStr}

var renameFunction = exports.renameFunction = function renameFunction(typeShorthands) {
var _rename = function _rename(oldFunctionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var newFunctionName = arguments[2];
var paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);
const renameFunction = exports.renameFunction = typeShorthands => {
const _rename = (oldFunctionName, functionParams = [], newFunctionName) => {
const paramsStr = (0, _utils.formatParams)(functionParams, typeShorthands);
return _utils.template`ALTER FUNCTION "${oldFunctionName}"${paramsStr} RENAME TO "${newFunctionName}";`;
};
_rename.reverse = function (oldFunctionName, functionParams, newFunctionName) {
return _rename(newFunctionName, functionParams, oldFunctionName);
};
_rename.reverse = (oldFunctionName, functionParams, newFunctionName) => _rename(newFunctionName, functionParams, oldFunctionName);
return _rename;
};

@@ -17,11 +17,9 @@ "use strict";

function generateIndexName(table, columns, options) {
return options.name ? options.name : function (tableName, cols, uniq) {
return _utils.template`${tableName}_${cols}${uniq}_index`;
}(typeof table === "object" ? table.name : table, _lodash2.default.isArray(columns) ? columns.join("_") : columns, options.unique ? "_unique" : "");
return options.name ? options.name : ((tableName, cols, uniq) => _utils.template`${tableName}_${cols}${uniq}_index`)(typeof table === "object" ? table.name : table, _lodash2.default.isArray(columns) ? columns.join("_") : columns, options.unique ? "_unique" : "");
}
function generateColumnString(column) {
var openingBracketPos = column.indexOf("(");
var closingBracketPos = column.indexOf(")");
var isFunction = openingBracketPos >= 0 && closingBracketPos > openingBracketPos;
const openingBracketPos = column.indexOf("(");
const closingBracketPos = column.indexOf(")");
const isFunction = openingBracketPos >= 0 && closingBracketPos > openingBracketPos;
return isFunction ? column // expression

@@ -35,5 +33,3 @@ : _utils.template`"${column}"`; // single column

var createIndex = exports.createIndex = function createIndex(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
const createIndex = exports.createIndex = (tableName, columns, options = {}) => {
/*

@@ -49,9 +45,9 @@ columns - the column, columns, or expression to create the index on

*/
var indexName = generateIndexName(tableName, columns, options);
var columnsString = generateColumnsString(columns);
var unique = options.unique ? " UNIQUE " : "";
var concurrently = options.concurrently ? " CONCURRENTLY " : "";
var method = options.method ? ` USING ${options.method}` : "";
var where = options.where ? ` WHERE ${options.where}` : "";
var opclass = options.opclass ? ` ${options.opclass}` : "";
const indexName = generateIndexName(tableName, columns, options);
const columnsString = generateColumnsString(columns);
const unique = options.unique ? " UNIQUE " : "";
const concurrently = options.concurrently ? " CONCURRENTLY " : "";
const method = options.method ? ` USING ${options.method}` : "";
const where = options.where ? ` WHERE ${options.where}` : "";
const opclass = options.opclass ? ` ${options.opclass}` : "";

@@ -61,12 +57,11 @@ return _utils.template`CREATE ${unique} INDEX ${concurrently} "${indexName}" ON "${tableName}"${method} (${columnsString})${opclass}${where};`;

var dropIndex = exports.dropIndex = function dropIndex(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var concurrently = options.concurrently,
ifExists = options.ifExists,
cascade = options.cascade;
const dropIndex = exports.dropIndex = (tableName, columns, options = {}) => {
const concurrently = options.concurrently,
ifExists = options.ifExists,
cascade = options.cascade;
var concurrentlyStr = concurrently ? " CONCURRENTLY" : "";
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var indexName = generateIndexName(tableName, columns, options);
var cascadeStr = cascade ? " CASCADE" : "";
const concurrentlyStr = concurrently ? " CONCURRENTLY" : "";
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const indexName = generateIndexName(tableName, columns, options);
const cascadeStr = cascade ? " CASCADE" : "";

@@ -73,0 +68,0 @@ return `DROP INDEX${concurrentlyStr}${ifExistsStr} "${indexName}"${cascadeStr};`;

@@ -10,16 +10,15 @@ "use strict";

var createOperator = exports.createOperator = function createOperator(operatorName) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var procedure = options.procedure,
left = options.left,
right = options.right,
commutator = options.commutator,
negator = options.negator,
restrict = options.restrict,
join = options.join,
hashes = options.hashes,
merges = options.merges;
const createOperator = exports.createOperator = (operatorName, options = {}) => {
const procedure = options.procedure,
left = options.left,
right = options.right,
commutator = options.commutator,
negator = options.negator,
restrict = options.restrict,
join = options.join,
hashes = options.hashes,
merges = options.merges;
var defs = [];
const defs = [];
defs.push(`PROCEDURE = ${(0, _utils.schemalize)(procedure)}`);

@@ -53,16 +52,15 @@ if (left) {

var dropOperator = exports.dropOperator = function dropOperator(operatorName) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var ifExists = options.ifExists,
cascade = options.cascade,
left = options.left,
right = options.right;
const dropOperator = exports.dropOperator = (operatorName, options = {}) => {
const ifExists = options.ifExists,
cascade = options.cascade,
left = options.left,
right = options.right;
var operatorNameStr = (0, _utils.schemalize)(operatorName);
var leftStr = (0, _utils.schemalize)(left || "none");
var rightStr = (0, _utils.schemalize)(right || "none");
const operatorNameStr = (0, _utils.schemalize)(operatorName);
const leftStr = (0, _utils.schemalize)(left || "none");
const rightStr = (0, _utils.schemalize)(right || "none");
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";

@@ -72,65 +70,55 @@ return `DROP OPERATOR${ifExistsStr} ${operatorNameStr}(${leftStr}, ${rightStr})${cascadeStr};`;

var createOperatorFamily = exports.createOperatorFamily = function createOperatorFamily(operatorFamilyName, indexMethod) {
var operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
const createOperatorFamily = exports.createOperatorFamily = (operatorFamilyName, indexMethod) => {
const operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
return `CREATE OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod};`;
};
var dropOperatorFamily = exports.dropOperatorFamily = function dropOperatorFamily(operatorFamilyName, indexMethod) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropOperatorFamily = exports.dropOperatorFamily = (operatorFamilyName, indexMethod, { ifExists, cascade } = {}) => {
const operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return `DROP OPERATOR FAMILY ${ifExistsStr} ${operatorFamilyNameStr} USING ${indexMethod}${cascadeStr};`;
};
var operatorMap = function operatorMap(typeShorthands) {
return function (_ref2) {
var _ref2$type = _ref2.type,
type = _ref2$type === undefined ? "" : _ref2$type,
number = _ref2.number,
name = _ref2.name,
_ref2$params = _ref2.params,
params = _ref2$params === undefined ? [] : _ref2$params;
const operatorMap = typeShorthands => ({
type = "",
number,
name,
params = []
}) => {
if (String(type).toLowerCase() === "function") {
if (params.length > 2) {
throw new Error("Operator can't have more than 2 parameters");
}
const nameStr = (0, _utils.schemalize)(name);
const paramsStr = params.length > 0 ? (0, _utils.formatParams)(params, typeShorthands) : "";
if (String(type).toLowerCase() === "function") {
if (params.length > 2) {
throw new Error("Operator can't have more than 2 parameters");
}
var nameStr = (0, _utils.schemalize)(name);
var paramsStr = params.length > 0 ? (0, _utils.formatParams)(params, typeShorthands) : "";
return `OPERATOR ${number} ${nameStr}${paramsStr}`;
} else if (String(type).toLowerCase() === "operator") {
var _paramsStr = (0, _utils.formatParams)(params, typeShorthands);
return `FUNCTION ${number} ${(0, _utils.schemalize)(name)}${_paramsStr}`;
}
throw new Error('Operator "type" must be either "function" or "operator"');
};
return `OPERATOR ${number} ${nameStr}${paramsStr}`;
} else if (String(type).toLowerCase() === "operator") {
const paramsStr = (0, _utils.formatParams)(params, typeShorthands);
return `FUNCTION ${number} ${(0, _utils.schemalize)(name)}${paramsStr}`;
}
throw new Error('Operator "type" must be either "function" or "operator"');
};
var changeOperatorFamily = exports.changeOperatorFamily = function changeOperatorFamily(op, reverse) {
return function (typeShorthands) {
var method = function method(operatorFamilyName, indexMethod, operatorList) {
var operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
var operatorListStr = operatorList.map(operatorMap(typeShorthands)).join(",\n ");
const changeOperatorFamily = exports.changeOperatorFamily = (op, reverse) => typeShorthands => {
const method = (operatorFamilyName, indexMethod, operatorList) => {
const operatorFamilyNameStr = (0, _utils.schemalize)(operatorFamilyName);
const operatorListStr = operatorList.map(operatorMap(typeShorthands)).join(",\n ");
return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ${op}
return `ALTER OPERATOR FAMILY ${operatorFamilyNameStr} USING ${indexMethod} ${op}
${operatorListStr};`;
};
if (reverse) {
method.reverse = reverse(typeShorthands);
}
return method;
};
if (reverse) {
method.reverse = reverse(typeShorthands);
}
return method;
};
var removeFromOperatorFamily = exports.removeFromOperatorFamily = changeOperatorFamily("DROP");
var addToOperatorFamily = exports.addToOperatorFamily = changeOperatorFamily("ADD", removeFromOperatorFamily);
const removeFromOperatorFamily = exports.removeFromOperatorFamily = changeOperatorFamily("DROP");
const addToOperatorFamily = exports.addToOperatorFamily = changeOperatorFamily("ADD", removeFromOperatorFamily);
var renameOperatorFamily = exports.renameOperatorFamily = function renameOperatorFamily(oldOperatorFamilyName, indexMethod, newOperatorFamilyName) {
var oldOperatorFamilyNameStr = (0, _utils.schemalize)(oldOperatorFamilyName);
var newOperatorFamilyNameStr = (0, _utils.schemalize)(newOperatorFamilyName);
const renameOperatorFamily = exports.renameOperatorFamily = (oldOperatorFamilyName, indexMethod, newOperatorFamilyName) => {
const oldOperatorFamilyNameStr = (0, _utils.schemalize)(oldOperatorFamilyName);
const newOperatorFamilyNameStr = (0, _utils.schemalize)(newOperatorFamilyName);

@@ -140,29 +128,23 @@ return `ALTER OPERATOR FAMILY ${oldOperatorFamilyNameStr} USING ${indexMethod} RENAME TO ${newOperatorFamilyNameStr};`;

var undoRenameOperatorFamily = function undoRenameOperatorFamily(oldOperatorFamilyName, indexMethod, newOperatorFamilyName) {
return renameOperatorFamily(newOperatorFamilyName, indexMethod, oldOperatorFamilyName);
};
const undoRenameOperatorFamily = (oldOperatorFamilyName, indexMethod, newOperatorFamilyName) => renameOperatorFamily(newOperatorFamilyName, indexMethod, oldOperatorFamilyName);
var dropOperatorClass = exports.dropOperatorClass = function dropOperatorClass(operatorClassName, indexMethod) {
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref3.ifExists,
cascade = _ref3.cascade;
const dropOperatorClass = exports.dropOperatorClass = (operatorClassName, indexMethod, { ifExists, cascade } = {}) => {
const operatorClassNameStr = (0, _utils.schemalize)(operatorClassName);
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
var operatorClassNameStr = (0, _utils.schemalize)(operatorClassName);
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
return `DROP OPERATOR CLASS ${ifExistsStr} ${operatorClassNameStr} USING ${indexMethod}${cascadeStr};`;
};
var createOperatorClass = exports.createOperatorClass = function createOperatorClass(typeShorthands) {
var _create = function _create(operatorClassName, type, indexMethod, operatorList, options) {
var isDefault = options.default,
family = options.family;
const createOperatorClass = exports.createOperatorClass = typeShorthands => {
const _create = (operatorClassName, type, indexMethod, operatorList, options) => {
const isDefault = options.default,
family = options.family;
var operatorClassNameStr = (0, _utils.schemalize)(operatorClassName);
var defaultStr = isDefault ? " DEFAULT" : "";
var typeStr = (0, _utils.schemalize)((0, _utils.applyType)(type).type);
var indexMethodStr = (0, _utils.schemalize)(indexMethod);
var familyStr = family ? ` FAMILY ${family}` : "";
var operatorListStr = operatorList.map(operatorMap(typeShorthands)).join(",\n ");
const operatorClassNameStr = (0, _utils.schemalize)(operatorClassName);
const defaultStr = isDefault ? " DEFAULT" : "";
const typeStr = (0, _utils.schemalize)((0, _utils.applyType)(type).type);
const indexMethodStr = (0, _utils.schemalize)(indexMethod);
const familyStr = family ? ` FAMILY ${family}` : "";
const operatorListStr = operatorList.map(operatorMap(typeShorthands)).join(",\n ");

@@ -172,11 +154,9 @@ return `CREATE OPERATOR CLASS ${operatorClassNameStr}${defaultStr} FOR TYPE ${typeStr} USING ${indexMethodStr} ${familyStr} AS

};
_create.reverse = function (operatorClassName, type, indexMethod, operatorList, options) {
return dropOperatorClass(operatorClassName, indexMethod, options);
};
_create.reverse = (operatorClassName, type, indexMethod, operatorList, options) => dropOperatorClass(operatorClassName, indexMethod, options);
return _create;
};
var renameOperatorClass = exports.renameOperatorClass = function renameOperatorClass(oldOperatorClassName, indexMethod, newOperatorClassName) {
var oldOperatorClassNameStr = (0, _utils.schemalize)(oldOperatorClassName);
var newOperatorClassNameStr = (0, _utils.schemalize)(newOperatorClassName);
const renameOperatorClass = exports.renameOperatorClass = (oldOperatorClassName, indexMethod, newOperatorClassName) => {
const oldOperatorClassNameStr = (0, _utils.schemalize)(oldOperatorClassName);
const newOperatorClassNameStr = (0, _utils.schemalize)(newOperatorClassName);

@@ -186,5 +166,3 @@ return `ALTER OPERATOR CLASS ${oldOperatorClassNameStr} USING ${indexMethod} RENAME TO ${newOperatorClassNameStr};`;

var undoRenameOperatorClass = function undoRenameOperatorClass(oldOperatorClassName, indexMethod, newOperatorClassName) {
return renameOperatorClass(newOperatorClassName, indexMethod, oldOperatorClassName);
};
const undoRenameOperatorClass = (oldOperatorClassName, indexMethod, newOperatorClassName) => renameOperatorClass(newOperatorClassName, indexMethod, oldOperatorClassName);

@@ -191,0 +169,0 @@ // setup reverse functions

@@ -11,5 +11,5 @@ "use strict";

// eslint-disable-next-line import/prefer-default-export
var sql = exports.sql = function sql() {
const sql = exports.sql = (...args) => {
// applies some very basic templating using the utils.p
var s = _utils.t.apply(undefined, arguments);
let s = (0, _utils.t)(...args);
// add trailing ; if not present

@@ -16,0 +16,0 @@ if (s.lastIndexOf(";") !== s.length - 1) {

@@ -12,11 +12,5 @@ "use strict";

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var makeClauses = function makeClauses(_ref) {
var role = _ref.role,
using = _ref.using,
check = _ref.check;
var roles = (Array.isArray(role) ? role : [role]).join(", ");
var clauses = [];
const makeClauses = ({ role, using, check }) => {
const roles = (Array.isArray(role) ? role : [role]).join(", ");
const clauses = [];
if (roles) {

@@ -34,35 +28,24 @@ clauses.push(`TO ${roles}`);

var createPolicy = exports.createPolicy = function createPolicy(tableName, policyName) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var createOptions = _extends({}, options, {
const createPolicy = exports.createPolicy = (tableName, policyName, options = {}) => {
const createOptions = _extends({}, options, {
role: options.role || "PUBLIC"
});
var clauses = [`FOR ${options.command || "ALL"}`].concat(_toConsumableArray(makeClauses(createOptions)));
var clausesStr = clauses.join(" ");
const clauses = [`FOR ${options.command || "ALL"}`, ...makeClauses(createOptions)];
const clausesStr = clauses.join(" ");
return _utils.template`CREATE POLICY "${policyName}" ON "${tableName}" ${clausesStr};`;
};
var alterPolicy = exports.alterPolicy = function alterPolicy(tableName, policyName) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var clausesStr = makeClauses(options).join(" ");
const alterPolicy = exports.alterPolicy = (tableName, policyName, options = {}) => {
const clausesStr = makeClauses(options).join(" ");
return _utils.template`ALTER POLICY "${policyName}" ON "${tableName}" ${clausesStr};`;
};
var dropPolicy = exports.dropPolicy = function dropPolicy(tableName, policyName) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref2.ifExists;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
const dropPolicy = exports.dropPolicy = (tableName, policyName, { ifExists } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
return _utils.template`DROP POLICY${ifExistsStr} "${policyName}" ON "${tableName}";`;
};
var renamePolicy = exports.renamePolicy = function renamePolicy(tableName, policyName, newPolicyName) {
return _utils.template`ALTER POLICY "${policyName}" ON "${tableName}" RENAME TO "${newPolicyName}";`;
};
const renamePolicy = exports.renamePolicy = (tableName, policyName, newPolicyName) => _utils.template`ALTER POLICY "${policyName}" ON "${tableName}" RENAME TO "${newPolicyName}";`;
var undoRename = function undoRename(tableName, policyName, newPolicyName) {
return renamePolicy(tableName, newPolicyName, policyName);
};
const undoRename = (tableName, policyName, newPolicyName) => renamePolicy(tableName, newPolicyName, policyName);

@@ -69,0 +52,0 @@ // setup reverse functions

@@ -14,6 +14,4 @@ "use strict";

var formatRoleOptions = function formatRoleOptions() {
var roleOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = [];
const formatRoleOptions = (roleOptions = {}) => {
const options = [];
if (roleOptions.superuser !== undefined) {

@@ -44,19 +42,19 @@ options.push(roleOptions.superuser ? "SUPERUSER" : "NOSUPERUSER");

if (roleOptions.password !== undefined) {
var encrypted = roleOptions.encrypted === false ? "UNENCRYPTED" : "ENCRYPTED";
const encrypted = roleOptions.encrypted === false ? "UNENCRYPTED" : "ENCRYPTED";
options.push(`${encrypted} PASSWORD ${(0, _utils.escapeValue)(roleOptions.password)}`);
}
if (roleOptions.valid !== undefined) {
var valid = roleOptions.valid ? (0, _utils.escapeValue)(roleOptions.valid) : "'infinity'";
const valid = roleOptions.valid ? (0, _utils.escapeValue)(roleOptions.valid) : "'infinity'";
options.push(`VALID UNTIL ${valid}`);
}
if (roleOptions.inRole) {
var inRole = (0, _lodash.isArray)(roleOptions.inRole) ? roleOptions.inRole.join(",") : roleOptions.inRole;
const inRole = (0, _lodash.isArray)(roleOptions.inRole) ? roleOptions.inRole.join(",") : roleOptions.inRole;
options.push(`IN ROLE ${inRole}`);
}
if (roleOptions.role) {
var role = (0, _lodash.isArray)(roleOptions.role) ? roleOptions.role.join(",") : roleOptions.role;
const role = (0, _lodash.isArray)(roleOptions.role) ? roleOptions.role.join(",") : roleOptions.role;
options.push(`ROLE ${role}`);
}
if (roleOptions.admin) {
var admin = (0, _lodash.isArray)(roleOptions.admin) ? roleOptions.admin.join(",") : roleOptions.admin;
const admin = (0, _lodash.isArray)(roleOptions.admin) ? roleOptions.admin.join(",") : roleOptions.admin;
options.push(`ADMIN ${admin}`);

@@ -68,6 +66,4 @@ }

var createRole = exports.createRole = function createRole(roleName) {
var roleOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = formatRoleOptions(_extends({}, roleOptions, {
const createRole = exports.createRole = (roleName, roleOptions = {}) => {
const options = formatRoleOptions(_extends({}, roleOptions, {
superuser: roleOptions.superuser || false,

@@ -80,27 +76,16 @@ createdb: roleOptions.createdb || false,

}));
var optionsStr = options ? ` WITH ${options}` : "";
const optionsStr = options ? ` WITH ${options}` : "";
return _utils.template`CREATE ROLE "${roleName}"${optionsStr};`;
};
var dropRole = exports.dropRole = function dropRole(roleName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists;
const dropRole = exports.dropRole = (roleName, { ifExists } = {}) => _utils.template`DROP ROLE${ifExists ? " IF EXISTS" : ""} "${roleName}";`;
return _utils.template`DROP ROLE${ifExists ? " IF EXISTS" : ""} "${roleName}";`;
};
var alterRole = exports.alterRole = function alterRole(roleName) {
var roleOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = formatRoleOptions(roleOptions);
const alterRole = exports.alterRole = (roleName, roleOptions = {}) => {
const options = formatRoleOptions(roleOptions);
return options ? _utils.template`ALTER ROLE "${roleName}" WITH ${options};` : "";
};
var renameRole = exports.renameRole = function renameRole(oldRoleName, newRoleName) {
return _utils.template`ALTER ROLE "${oldRoleName}" RENAME TO "${newRoleName}";`;
};
const renameRole = exports.renameRole = (oldRoleName, newRoleName) => _utils.template`ALTER ROLE "${oldRoleName}" RENAME TO "${newRoleName}";`;
var undoRename = function undoRename(oldRoleName, newRoleName) {
return renameRole(newRoleName, oldRoleName);
};
const undoRename = (oldRoleName, newRoleName) => renameRole(newRoleName, oldRoleName);

@@ -107,0 +92,0 @@ // setup reverse functions

@@ -10,31 +10,19 @@ "use strict";

var dropSchema = exports.dropSchema = function dropSchema(schemaName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropSchema = exports.dropSchema = (schemaName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP SCHEMA${ifExistsStr} "${schemaName}"${cascadeStr};`;
};
var createSchema = exports.createSchema = function createSchema(schemaName) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifNotExists = _ref2.ifNotExists,
authorization = _ref2.authorization;
var ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
var authorizationStr = authorization ? ` AUTHORIZATION ${authorization}` : "";
const createSchema = exports.createSchema = (schemaName, { ifNotExists, authorization } = {}) => {
const ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
const authorizationStr = authorization ? ` AUTHORIZATION ${authorization}` : "";
return _utils.template`CREATE SCHEMA${ifNotExistsStr} "${schemaName}"${authorizationStr};`;
};
var renameSchema = exports.renameSchema = function renameSchema(schemaName, newSchemaName) {
return _utils.template`ALTER SCHEMA "${schemaName}" RENAME TO "${newSchemaName}";`;
};
const renameSchema = exports.renameSchema = (schemaName, newSchemaName) => _utils.template`ALTER SCHEMA "${schemaName}" RENAME TO "${newSchemaName}";`;
var undoRename = function undoRename(schemaName, newSchemaName) {
return renameSchema(newSchemaName, schemaName);
};
const undoRename = (schemaName, newSchemaName) => renameSchema(newSchemaName, schemaName);
createSchema.reverse = dropSchema;
renameSchema.reverse = undoRename;

@@ -10,13 +10,13 @@ "use strict";

var parseOptions = function parseOptions(typeShorthands, options) {
var type = options.type,
increment = options.increment,
minvalue = options.minvalue,
maxvalue = options.maxvalue,
start = options.start,
cache = options.cache,
cycle = options.cycle,
owner = options.owner;
const parseOptions = (typeShorthands, options) => {
const type = options.type,
increment = options.increment,
minvalue = options.minvalue,
maxvalue = options.maxvalue,
start = options.start,
cache = options.cache,
cycle = options.cycle,
owner = options.owner;
var clauses = [];
const clauses = [];
if (type) {

@@ -57,21 +57,16 @@ clauses.push(`AS ${(0, _utils.applyType)(type, typeShorthands).type}`);

var dropSequence = exports.dropSequence = function dropSequence(sequenceName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropSequence = exports.dropSequence = (sequenceName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP SEQUENCE${ifExistsStr} "${sequenceName}"${cascadeStr};`;
};
var createSequence = exports.createSequence = function createSequence(typeShorthands) {
var _create = function _create(sequenceName) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var temporary = options.temporary,
ifNotExists = options.ifNotExists;
const createSequence = exports.createSequence = typeShorthands => {
const _create = (sequenceName, options = {}) => {
const temporary = options.temporary,
ifNotExists = options.ifNotExists;
var temporaryStr = temporary ? " TEMPORARY" : "";
var ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
var clausesStr = parseOptions(typeShorthands, options).join("\n ");
const temporaryStr = temporary ? " TEMPORARY" : "";
const ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
const clausesStr = parseOptions(typeShorthands, options).join("\n ");
return _utils.template`CREATE${temporaryStr} SEQUENCE${ifNotExistsStr} "${sequenceName}"

@@ -84,27 +79,21 @@ ${clausesStr};`;

var alterSequence = exports.alterSequence = function alterSequence(typeShorthands) {
return function (sequenceName, options) {
var restart = options.restart;
const alterSequence = exports.alterSequence = typeShorthands => (sequenceName, options) => {
const restart = options.restart;
var clauses = parseOptions(typeShorthands, options);
if (restart) {
if (restart === true) {
clauses.push("RESTART");
} else {
clauses.push(`RESTART WITH ${restart}`);
}
const clauses = parseOptions(typeShorthands, options);
if (restart) {
if (restart === true) {
clauses.push("RESTART");
} else {
clauses.push(`RESTART WITH ${restart}`);
}
return _utils.template`ALTER SEQUENCE "${sequenceName}"
}
return _utils.template`ALTER SEQUENCE "${sequenceName}"
${clauses.join("\n ")};`;
};
};
var renameSequence = exports.renameSequence = function renameSequence(sequenceName, newSequenceName) {
return _utils.template`ALTER SEQUENCE "${sequenceName}" RENAME TO "${newSequenceName}";`;
};
const renameSequence = exports.renameSequence = (sequenceName, newSequenceName) => _utils.template`ALTER SEQUENCE "${sequenceName}" RENAME TO "${newSequenceName}";`;
var undoRename = function undoRename(sequenceName, newSequenceName) {
return renameSequence(newSequenceName, sequenceName);
};
const undoRename = (sequenceName, newSequenceName) => renameSequence(newSequenceName, sequenceName);
renameSequence.reverse = undoRename;

@@ -18,11 +18,9 @@ "use strict";

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const parseReferences = options => {
const references = options.references,
match = options.match,
onDelete = options.onDelete,
onUpdate = options.onUpdate;
var parseReferences = function parseReferences(options) {
var references = options.references,
match = options.match,
onDelete = options.onDelete,
onUpdate = options.onUpdate;
var clauses = [typeof references === "string" ? `REFERENCES ${references}` : _utils.template`REFERENCES "${references}"`];
const clauses = [typeof references === "string" ? `REFERENCES ${references}` : _utils.template`REFERENCES "${references}"`];
if (match) {

@@ -40,5 +38,5 @@ clauses.push(`MATCH ${match}`);

var parseDeferrable = function parseDeferrable(options) {
var deferrable = options.deferrable,
deferred = options.deferred;
const parseDeferrable = options => {
const deferrable = options.deferrable,
deferred = options.deferred;

@@ -48,39 +46,29 @@ return deferrable ? `DEFERRABLE INITIALLY ${deferred ? "DEFERRED" : "IMMEDIATE"}` : null;

var parseColumns = function parseColumns(tableName, columns) {
var extendingTypeShorthands = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
const parseColumns = (tableName, columns, extendingTypeShorthands = {}) => {
let columnsWithOptions = _lodash2.default.mapValues(columns, column => (0, _utils.applyType)(column, extendingTypeShorthands));
var columnsWithOptions = _lodash2.default.mapValues(columns, function (column) {
return (0, _utils.applyType)(column, extendingTypeShorthands);
});
const primaryColumns = _lodash2.default.chain(columnsWithOptions).map((options, columnName) => options.primaryKey ? columnName : null).filter().value();
const multiplePrimaryColumns = primaryColumns.length > 1;
var primaryColumns = _lodash2.default.chain(columnsWithOptions).map(function (options, columnName) {
return options.primaryKey ? columnName : null;
}).filter().value();
var multiplePrimaryColumns = primaryColumns.length > 1;
if (multiplePrimaryColumns) {
columnsWithOptions = _lodash2.default.mapValues(columnsWithOptions, function (options) {
return _extends({}, options, {
primaryKey: false
});
});
columnsWithOptions = _lodash2.default.mapValues(columnsWithOptions, options => _extends({}, options, {
primaryKey: false
}));
}
var comments = _lodash2.default.chain(columnsWithOptions).map(function (options, columnName) {
return typeof options.comment !== "undefined" && (0, _utils.comment)("COLUMN", `${(0, _utils.schemalize)(tableName)}"."${columnName}`, options.comment);
}).filter().value();
const comments = _lodash2.default.chain(columnsWithOptions).map((options, columnName) => typeof options.comment !== "undefined" && (0, _utils.comment)("COLUMN", `${(0, _utils.schemalize)(tableName)}"."${columnName}`, options.comment)).filter().value();
return {
columns: _lodash2.default.map(columnsWithOptions, function (options, columnName) {
var type = options.type,
collation = options.collation,
defaultValue = options.default,
unique = options.unique,
primaryKey = options.primaryKey,
notNull = options.notNull,
check = options.check,
references = options.references,
deferrable = options.deferrable;
columns: _lodash2.default.map(columnsWithOptions, (options, columnName) => {
const type = options.type,
collation = options.collation,
defaultValue = options.default,
unique = options.unique,
primaryKey = options.primaryKey,
notNull = options.notNull,
check = options.check,
references = options.references,
deferrable = options.deferrable;
var constraints = [];
const constraints = [];
if (collation) {

@@ -111,5 +99,5 @@ constraints.push(`COLLATE ${collation}`);

var constraintsStr = constraints.length ? ` ${constraints.join(" ")}` : "";
const constraintsStr = constraints.length ? ` ${constraints.join(" ")}` : "";
var sType = typeof type === "object" ? `"${(0, _utils.schemalize)(type)}"` : type;
const sType = typeof type === "object" ? `"${(0, _utils.schemalize)(type)}"` : type;

@@ -123,24 +111,22 @@ return _utils.template`"${columnName}" ${sType}${constraintsStr}`;

var parseConstraints = function parseConstraints(table, options, genName) {
var check = options.check,
unique = options.unique,
primaryKey = options.primaryKey,
foreignKeys = options.foreignKeys,
exclude = options.exclude,
deferrable = options.deferrable;
const parseConstraints = (table, options, genName) => {
const check = options.check,
unique = options.unique,
primaryKey = options.primaryKey,
foreignKeys = options.foreignKeys,
exclude = options.exclude,
deferrable = options.deferrable;
var tableName = typeof table === "object" ? table.name : table;
var constraints = [];
const tableName = typeof table === "object" ? table.name : table;
const constraints = [];
if (check) {
var name = genName ? `CONSTRAINT "${tableName}_chck" ` : "";
const name = genName ? `CONSTRAINT "${tableName}_chck" ` : "";
constraints.push(`${name}CHECK (${check})`);
}
if (unique) {
var uniqueArray = _lodash2.default.isArray(unique) ? unique : [unique];
var isArrayOfArrays = uniqueArray.some(function (uniqueSet) {
return _lodash2.default.isArray(uniqueSet);
});
(isArrayOfArrays ? uniqueArray : [uniqueArray]).forEach(function (uniqueSet) {
var cols = _lodash2.default.isArray(uniqueSet) ? uniqueSet : [uniqueSet];
var name = genName ? `CONSTRAINT "${tableName}_uniq_${cols.join("_")}" ` : "";
const uniqueArray = _lodash2.default.isArray(unique) ? unique : [unique];
const isArrayOfArrays = uniqueArray.some(uniqueSet => _lodash2.default.isArray(uniqueSet));
(isArrayOfArrays ? uniqueArray : [uniqueArray]).forEach(uniqueSet => {
const cols = _lodash2.default.isArray(uniqueSet) ? uniqueSet : [uniqueSet];
const name = genName ? `CONSTRAINT "${tableName}_uniq_${cols.join("_")}" ` : "";
constraints.push(`${name}UNIQUE (${(0, _utils.quote)(cols).join(", ")})`);

@@ -150,13 +136,13 @@ });

if (primaryKey) {
var _name = genName ? `CONSTRAINT "${tableName}_pkey" ` : "";
var key = (0, _utils.quote)(_lodash2.default.isArray(primaryKey) ? primaryKey : [primaryKey]).join(", ");
constraints.push(`${_name}PRIMARY KEY (${key})`);
const name = genName ? `CONSTRAINT "${tableName}_pkey" ` : "";
const key = (0, _utils.quote)(_lodash2.default.isArray(primaryKey) ? primaryKey : [primaryKey]).join(", ");
constraints.push(`${name}PRIMARY KEY (${key})`);
}
if (foreignKeys) {
(_lodash2.default.isArray(foreignKeys) ? foreignKeys : [foreignKeys]).forEach(function (fk) {
var columns = fk.columns;
(_lodash2.default.isArray(foreignKeys) ? foreignKeys : [foreignKeys]).forEach(fk => {
const columns = fk.columns;
var cols = _lodash2.default.isArray(columns) ? columns : [columns];
var name = genName ? `CONSTRAINT "${tableName}_fk_${cols.join("_")}" ` : "";
var key = (0, _utils.quote)(cols).join(", ");
const cols = _lodash2.default.isArray(columns) ? columns : [columns];
const name = genName ? `CONSTRAINT "${tableName}_fk_${cols.join("_")}" ` : "";
const key = (0, _utils.quote)(cols).join(", ");
constraints.push(`${name}FOREIGN KEY (${key}) ${parseReferences(fk)}`);

@@ -166,57 +152,51 @@ });

if (exclude) {
var _name2 = genName ? `CONSTRAINT "${tableName}_excl" ` : "";
constraints.push(`${_name2}EXCLUDE ${exclude}`);
const name = genName ? `CONSTRAINT "${tableName}_excl" ` : "";
constraints.push(`${name}EXCLUDE ${exclude}`);
}
return deferrable ? constraints.map(function (constraint) {
return `${constraint} ${parseDeferrable(options)}`;
}) : constraints;
return deferrable ? constraints.map(constraint => `${constraint} ${parseDeferrable(options)}`) : constraints;
};
// TABLE
var dropTable = exports.dropTable = function dropTable(tableName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropTable = exports.dropTable = (tableName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP TABLE${ifExistsStr} "${tableName}"${cascadeStr};`;
};
var createTable = exports.createTable = function createTable(typeShorthands) {
var _create = function _create(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var temporary = options.temporary,
ifNotExists = options.ifNotExists,
inherits = options.inherits,
like = options.like,
_options$constraints = options.constraints,
optionsConstraints = _options$constraints === undefined ? {} : _options$constraints,
tableComment = options.comment;
const createTable = exports.createTable = typeShorthands => {
const _create = (tableName, columns, options = {}) => {
const temporary = options.temporary,
ifNotExists = options.ifNotExists,
inherits = options.inherits,
like = options.like;
var _options$constraints = options.constraints;
const optionsConstraints = _options$constraints === undefined ? {} : _options$constraints,
tableComment = options.comment;
var _parseColumns = parseColumns(tableName, columns, typeShorthands),
columnLines = _parseColumns.columns,
columnsConstraints = _parseColumns.constraints,
_parseColumns$comment = _parseColumns.comments,
columnComments = _parseColumns$comment === undefined ? [] : _parseColumns$comment;
var _parseColumns = parseColumns(tableName, columns, typeShorthands);
var dupes = _lodash2.default.intersection(Object.keys(optionsConstraints), Object.keys(columnsConstraints));
const columnLines = _parseColumns.columns,
columnsConstraints = _parseColumns.constraints;
var _parseColumns$comment = _parseColumns.comments;
const columnComments = _parseColumns$comment === undefined ? [] : _parseColumns$comment;
const dupes = _lodash2.default.intersection(Object.keys(optionsConstraints), Object.keys(columnsConstraints));
if (dupes.length > 0) {
var dupesStr = dupes.join(", ");
const dupesStr = dupes.join(", ");
throw new Error(`There is duplicate constraint definition in table and columns options: ${dupesStr}`);
}
var constraints = _extends({}, optionsConstraints, columnsConstraints);
var constraintLines = parseConstraints(tableName, constraints, true);
var tableDefinition = [].concat(_toConsumableArray(columnLines), _toConsumableArray(constraintLines)).concat(like ? [_utils.template`LIKE "${like}"`] : []);
const constraints = _extends({}, optionsConstraints, columnsConstraints);
const constraintLines = parseConstraints(tableName, constraints, true);
const tableDefinition = [...columnLines, ...constraintLines].concat(like ? [_utils.template`LIKE "${like}"`] : []);
var temporaryStr = temporary ? " TEMPORARY" : "";
var ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
var inheritsStr = inherits ? _utils.template` INHERITS ("${inherits}")` : "";
const temporaryStr = temporary ? " TEMPORARY" : "";
const ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
const inheritsStr = inherits ? _utils.template` INHERITS ("${inherits}")` : "";
var createTableQuery = _utils.template`CREATE TABLE${temporaryStr}${ifNotExistsStr} "${tableName}" (
const createTableQuery = _utils.template`CREATE TABLE${temporaryStr}${ifNotExistsStr} "${tableName}" (
${(0, _utils.formatLines)(tableDefinition)}
)${inheritsStr};`;
var comments = columnComments;
const comments = columnComments;
if (typeof tableComment !== "undefined") {

@@ -231,4 +211,4 @@ comments.push((0, _utils.comment)("TABLE ", tableName, tableComment));

var alterTable = exports.alterTable = function alterTable(tableName, options) {
var alterDefinition = [];
const alterTable = exports.alterTable = (tableName, options) => {
const alterDefinition = [];
if (options.levelSecurity) {

@@ -242,7 +222,3 @@ alterDefinition.push(`${options.levelSecurity} ROW LEVEL SECURITY`);

// COLUMNS
var dropColumns = exports.dropColumns = function dropColumns(tableName, columns) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref2.ifExists,
cascade = _ref2.cascade;
const dropColumns = exports.dropColumns = (tableName, columns, { ifExists, cascade } = {}) => {
if (typeof columns === "string") {

@@ -253,3 +229,3 @@ columns = [columns]; // eslint-disable-line no-param-reassign

}
var columnsStr = (0, _utils.formatLines)((0, _utils.quote)(columns), ` DROP ${ifExists ? " IF EXISTS" : ""}`, `${cascade ? " CASCADE" : ""},`);
const columnsStr = (0, _utils.formatLines)((0, _utils.quote)(columns), ` DROP ${ifExists ? " IF EXISTS" : ""}`, `${cascade ? " CASCADE" : ""},`);
return _utils.template`ALTER TABLE "${tableName}"

@@ -259,12 +235,13 @@ ${columnsStr};`;

var addColumns = exports.addColumns = function addColumns(typeShorthands) {
var _add = function _add(tableName, columns) {
var _parseColumns2 = parseColumns(tableName, columns, typeShorthands),
columnLines = _parseColumns2.columns,
_parseColumns2$commen = _parseColumns2.comments,
columnComments = _parseColumns2$commen === undefined ? [] : _parseColumns2$commen;
const addColumns = exports.addColumns = typeShorthands => {
const _add = (tableName, columns) => {
var _parseColumns2 = parseColumns(tableName, columns, typeShorthands);
var columnsStr = (0, _utils.formatLines)(columnLines, " ADD ");
var alterTableQuery = _utils.template`ALTER TABLE "${tableName}"\n${columnsStr};`;
var columnCommentsStr = columnComments.length > 0 ? `\n${columnComments.join("\n")}` : "";
const columnLines = _parseColumns2.columns;
var _parseColumns2$commen = _parseColumns2.comments;
const columnComments = _parseColumns2$commen === undefined ? [] : _parseColumns2$commen;
const columnsStr = (0, _utils.formatLines)(columnLines, " ADD ");
const alterTableQuery = _utils.template`ALTER TABLE "${tableName}"\n${columnsStr};`;
const columnCommentsStr = columnComments.length > 0 ? `\n${columnComments.join("\n")}` : "";
return `${alterTableQuery}${columnCommentsStr}`;

@@ -276,12 +253,12 @@ };

var alterColumn = exports.alterColumn = function alterColumn(tableName, columnName, options) {
var defaultValue = options.default,
type = options.type,
collation = options.collation,
using = options.using,
notNull = options.notNull,
allowNull = options.allowNull,
columnComment = options.comment;
const alterColumn = exports.alterColumn = (tableName, columnName, options) => {
const defaultValue = options.default,
type = options.type,
collation = options.collation,
using = options.using,
notNull = options.notNull,
allowNull = options.allowNull,
columnComment = options.comment;
var actions = [];
const actions = [];
if (defaultValue === null) {

@@ -293,5 +270,5 @@ actions.push("DROP DEFAULT");

if (type) {
var typeStr = (0, _utils.applyTypeAdapters)(type);
var collationStr = collation ? `COLLATE ${collation}` : "";
var usingStr = using ? ` USING ${using}` : "";
const typeStr = (0, _utils.applyTypeAdapters)(type);
const collationStr = collation ? `COLLATE ${collation}` : "";
const usingStr = using ? ` USING ${using}` : "";
actions.push(`SET DATA TYPE ${typeStr}${collationStr}${usingStr}`);

@@ -305,43 +282,28 @@ }

var columnsStr = (0, _utils.formatLines)(actions, ` ALTER "${columnName}" `);
var columnCommentStr = typeof columnComment !== "undefined" ? `\n${(0, _utils.comment)("TABLE ", columnName, columnComment)}` : "";
const columnsStr = (0, _utils.formatLines)(actions, ` ALTER "${columnName}" `);
const columnCommentStr = typeof columnComment !== "undefined" ? `\n${(0, _utils.comment)("TABLE ", columnName, columnComment)}` : "";
return _utils.template`ALTER TABLE "${tableName}"\n${columnsStr};${columnCommentStr}`;
};
var renameTable = exports.renameTable = function renameTable(tableName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME TO "${newName}";`;
};
const renameTable = exports.renameTable = (tableName, newName) => _utils.template`ALTER TABLE "${tableName}" RENAME TO "${newName}";`;
var undoRenameTable = function undoRenameTable(tableName, newName) {
return renameTable(newName, tableName);
};
const undoRenameTable = (tableName, newName) => renameTable(newName, tableName);
var renameColumn = exports.renameColumn = function renameColumn(tableName, columnName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME "${columnName}" TO "${newName}";`;
};
const renameColumn = exports.renameColumn = (tableName, columnName, newName) => _utils.template`ALTER TABLE "${tableName}" RENAME "${columnName}" TO "${newName}";`;
var undoRenameColumn = function undoRenameColumn(tableName, columnName, newName) {
return renameColumn(tableName, newName, columnName);
};
const undoRenameColumn = (tableName, columnName, newName) => renameColumn(tableName, newName, columnName);
var renameConstraint = exports.renameConstraint = function renameConstraint(tableName, constraintName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME CONSTRAINT "${constraintName}" TO "${newName}";`;
};
const renameConstraint = exports.renameConstraint = (tableName, constraintName, newName) => _utils.template`ALTER TABLE "${tableName}" RENAME CONSTRAINT "${constraintName}" TO "${newName}";`;
var undoRenameConstraint = function undoRenameConstraint(tableName, constraintName, newName) {
return renameConstraint(tableName, newName, constraintName);
};
const undoRenameConstraint = (tableName, constraintName, newName) => renameConstraint(tableName, newName, constraintName);
var addConstraint = exports.addConstraint = function addConstraint(tableName, constraintName, expression) {
var constraintStr = (0, _utils.formatLines)(typeof expression === "string" ? [expression] : parseConstraints(tableName, expression, false), ` ADD CONSTRAINT "${constraintName}" `);
const addConstraint = exports.addConstraint = (tableName, constraintName, expression) => {
const constraint = constraintName ? `CONSTRAINT "${constraintName}" ` : "";
const constraintStr = (0, _utils.formatLines)(typeof expression === "string" ? [expression] : parseConstraints(tableName, expression, false), ` ADD ${constraint}`);
return _utils.template`ALTER TABLE "${tableName}"\n${constraintStr};`;
};
var dropConstraint = exports.dropConstraint = function dropConstraint(tableName, constraintName) {
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref3.ifExists,
cascade = _ref3.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropConstraint = exports.dropConstraint = (tableName, constraintName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`ALTER TABLE "${tableName}" DROP CONSTRAINT${ifExistsStr} "${constraintName}"${cascadeStr};`;

@@ -348,0 +310,0 @@ };

@@ -16,32 +16,26 @@ "use strict";

var dropTrigger = exports.dropTrigger = function dropTrigger(tableName, triggerName) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropTrigger = exports.dropTrigger = (tableName, triggerName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP TRIGGER${ifExistsStr} "${triggerName}" ON "${tableName}"${cascadeStr};`;
};
var createTrigger = exports.createTrigger = function createTrigger(typeShorthands) {
var _create = function _create(tableName, triggerName) {
var triggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
var constraint = triggerOptions.constraint,
condition = triggerOptions.condition,
operation = triggerOptions.operation,
deferrable = triggerOptions.deferrable,
deferred = triggerOptions.deferred,
_triggerOptions$funct = triggerOptions.functionArgs,
functionArgs = _triggerOptions$funct === undefined ? [] : _triggerOptions$funct;
var when = triggerOptions.when,
_triggerOptions$level = triggerOptions.level,
level = _triggerOptions$level === undefined ? "STATEMENT" : _triggerOptions$level,
const createTrigger = exports.createTrigger = typeShorthands => {
const _create = (tableName, triggerName, triggerOptions = {}, definition) => {
const constraint = triggerOptions.constraint,
condition = triggerOptions.condition,
operation = triggerOptions.operation,
deferrable = triggerOptions.deferrable,
deferred = triggerOptions.deferred;
var _triggerOptions$funct = triggerOptions.functionArgs;
const functionArgs = _triggerOptions$funct === undefined ? [] : _triggerOptions$funct;
let when = triggerOptions.when;
var _triggerOptions$level = triggerOptions.level;
let level = _triggerOptions$level === undefined ? "STATEMENT" : _triggerOptions$level,
functionName = triggerOptions.function;
var operations = (0, _lodash.isArray)(operation) ? operation.join(" OR ") : operation;
const operations = (0, _lodash.isArray)(operation) ? operation.join(" OR ") : operation;
if (constraint) {
when = "AFTER";
}
var isInsteadOf = /instead\s+of/i.test(when);
const isInsteadOf = /instead\s+of/i.test(when);
if (isInsteadOf) {

@@ -63,8 +57,8 @@ level = "ROW";

var defferStr = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? "DEFERRED" : "IMMEDIATE"}` : "NOT DEFERRABLE"}\n ` : "";
var conditionClause = condition ? `WHEN (${condition})\n ` : "";
var constraintStr = constraint ? " CONSTRAINT" : "";
var paramsStr = functionArgs.map(_utils.escapeValue).join(", ");
const defferStr = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? "DEFERRED" : "IMMEDIATE"}` : "NOT DEFERRABLE"}\n ` : "";
const conditionClause = condition ? `WHEN (${condition})\n ` : "";
const constraintStr = constraint ? " CONSTRAINT" : "";
const paramsStr = functionArgs.map(_utils.escapeValue).join(", ");
var triggerSQL = _utils.template`CREATE${constraintStr} TRIGGER "${triggerName}"
const triggerSQL = _utils.template`CREATE${constraintStr} TRIGGER "${triggerName}"
${when} ${operations} ON "${tableName}"

@@ -74,12 +68,9 @@ ${defferStr}FOR EACH ${level}

var fnSQL = definition ? `${(0, _functions.createFunction)(typeShorthands)(functionName, [], _extends({}, triggerOptions, { returns: "trigger" }), definition)}\n` : "";
const fnSQL = definition ? `${(0, _functions.createFunction)(typeShorthands)(functionName, [], _extends({}, triggerOptions, { returns: "trigger" }), definition)}\n` : "";
return `${fnSQL}${triggerSQL}`;
};
_create.reverse = function (tableName, triggerName) {
var triggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
var triggerSQL = dropTrigger(tableName, triggerName, triggerOptions);
var fnSQL = definition ? `\n${(0, _functions.dropFunction)(typeShorthands)(triggerOptions.function || triggerName, [], triggerOptions)}` : "";
_create.reverse = (tableName, triggerName, triggerOptions = {}, definition) => {
const triggerSQL = dropTrigger(tableName, triggerName, triggerOptions);
const fnSQL = definition ? `\n${(0, _functions.dropFunction)(typeShorthands)(triggerOptions.function || triggerName, [], triggerOptions)}` : "";
return `${triggerSQL}${fnSQL}`;

@@ -91,10 +82,6 @@ };

var renameTrigger = exports.renameTrigger = function renameTrigger(tableName, oldTriggerName, newTriggerName) {
return _utils.template`ALTER TRIGGER "${oldTriggerName}" ON "${tableName}" RENAME TO "${newTriggerName}";`;
};
const renameTrigger = exports.renameTrigger = (tableName, oldTriggerName, newTriggerName) => _utils.template`ALTER TRIGGER "${oldTriggerName}" ON "${tableName}" RENAME TO "${newTriggerName}";`;
var undoRename = function undoRename(tableName, oldTriggerName, newTriggerName) {
return renameTrigger(tableName, newTriggerName, oldTriggerName);
};
const undoRename = (tableName, oldTriggerName, newTriggerName) => renameTrigger(tableName, newTriggerName, oldTriggerName);
renameTrigger.reverse = undoRename;

@@ -16,20 +16,16 @@ "use strict";

var dropType = exports.dropType = function dropType(typeName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropType = exports.dropType = (typeName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP TYPE${ifExistsStr} "${typeName}"${cascadeStr};`;
};
var createType = exports.createType = function createType(typeShorthands) {
var _create = function _create(typeName, options) {
const createType = exports.createType = typeShorthands => {
const _create = (typeName, options) => {
if (_lodash2.default.isArray(options)) {
var optionsStr = options.map(_utils.escapeValue).join(", ");
const optionsStr = options.map(_utils.escapeValue).join(", ");
return _utils.template`CREATE TYPE "${typeName}" AS ENUM (${optionsStr});`;
}
var attributes = _lodash2.default.map(options, function (attribute, attributeName) {
var typeStr = (0, _utils.applyType)(attribute, typeShorthands).type;
const attributes = _lodash2.default.map(options, (attribute, attributeName) => {
const typeStr = (0, _utils.applyType)(attribute, typeShorthands).type;
return _utils.template`"${attributeName}" ${typeStr}`;

@@ -43,13 +39,10 @@ }).join(",\n");

var dropTypeAttribute = exports.dropTypeAttribute = function dropTypeAttribute(typeName, attributeName) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref2.ifExists;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
const dropTypeAttribute = exports.dropTypeAttribute = (typeName, attributeName, { ifExists } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
return _utils.template`ALTER TYPE "${typeName}" DROP ATTRIBUTE "${attributeName}"${ifExistsStr};`;
};
var addTypeAttribute = exports.addTypeAttribute = function addTypeAttribute(typeShorthands) {
var _alterAttributeAdd = function _alterAttributeAdd(typeName, attributeName, attributeType) {
var typeStr = (0, _utils.applyType)(attributeType, typeShorthands).type;
const addTypeAttribute = exports.addTypeAttribute = typeShorthands => {
const _alterAttributeAdd = (typeName, attributeName, attributeType) => {
const typeStr = (0, _utils.applyType)(attributeType, typeShorthands).type;

@@ -62,14 +55,11 @@ return _utils.template`ALTER TYPE "${typeName}" ADD ATTRIBUTE "${attributeName}" ${typeStr};`;

var setTypeAttribute = exports.setTypeAttribute = function setTypeAttribute(typeShorthands) {
return function (typeName, attributeName, attributeType) {
var typeStr = (0, _utils.applyType)(attributeType, typeShorthands).type;
const setTypeAttribute = exports.setTypeAttribute = typeShorthands => (typeName, attributeName, attributeType) => {
const typeStr = (0, _utils.applyType)(attributeType, typeShorthands).type;
return _utils.template`ALTER TYPE "${typeName}" ALTER ATTRIBUTE "${attributeName}" SET DATA TYPE ${typeStr};`;
};
return _utils.template`ALTER TYPE "${typeName}" ALTER ATTRIBUTE "${attributeName}" SET DATA TYPE ${typeStr};`;
};
var addTypeValue = exports.addTypeValue = function addTypeValue(typeName, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var ifNotExists = options.ifNotExists,
before = options.before,
after = options.after;
const addTypeValue = exports.addTypeValue = (typeName, value, options = {}) => {
const ifNotExists = options.ifNotExists,
before = options.before,
after = options.after;

@@ -80,6 +70,6 @@

}
var beforeStr = before ? ` BEFORE ${before}` : "";
var afterStr = after ? ` AFTER ${after}` : "";
var ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
var valueStr = (0, _utils.escapeValue)(value);
const beforeStr = before ? ` BEFORE ${before}` : "";
const afterStr = after ? ` AFTER ${after}` : "";
const ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
const valueStr = (0, _utils.escapeValue)(value);

@@ -89,19 +79,11 @@ return _utils.template`ALTER TYPE "${typeName}" ADD VALUE${ifNotExistsStr} ${valueStr}${beforeStr}${afterStr};`;

var renameType = exports.renameType = function renameType(typeName, newTypeName) {
return _utils.template`ALTER TYPE "${typeName}" RENAME TO "${newTypeName}";`;
};
const renameType = exports.renameType = (typeName, newTypeName) => _utils.template`ALTER TYPE "${typeName}" RENAME TO "${newTypeName}";`;
var undoRename = function undoRename(typeName, newTypeName) {
return renameType(newTypeName, typeName);
};
const undoRename = (typeName, newTypeName) => renameType(newTypeName, typeName);
var renameTypeAttribute = exports.renameTypeAttribute = function renameTypeAttribute(typeName, attributeName, newAttributeName) {
return _utils.template`ALTER TYPE "${typeName}" RENAME ATTRIBUTE "${attributeName}" TO "${newAttributeName}";`;
};
const renameTypeAttribute = exports.renameTypeAttribute = (typeName, attributeName, newAttributeName) => _utils.template`ALTER TYPE "${typeName}" RENAME ATTRIBUTE "${attributeName}" TO "${newAttributeName}";`;
var undoRenameTypeAttribute = exports.undoRenameTypeAttribute = function undoRenameTypeAttribute(typeName, attributeName, newAttributeName) {
return renameTypeAttribute(typeName, newAttributeName, attributeName);
};
const undoRenameTypeAttribute = exports.undoRenameTypeAttribute = (typeName, attributeName, newAttributeName) => renameTypeAttribute(typeName, newAttributeName, attributeName);
renameType.reverse = undoRename;
renameTypeAttribute.reverse = undoRenameTypeAttribute;

@@ -10,27 +10,23 @@ "use strict";

var dropView = exports.dropView = function dropView(viewName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropView = exports.dropView = (viewName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP VIEW${ifExistsStr} "${viewName}"${cascadeStr};`;
};
var createView = exports.createView = function createView(viewName, options, definition) {
var temporary = options.temporary,
replace = options.replace,
recursive = options.recursive,
_options$columns = options.columns,
columns = _options$columns === undefined ? [] : _options$columns,
checkOption = options.checkOption;
const createView = exports.createView = (viewName, options, definition) => {
const temporary = options.temporary,
replace = options.replace,
recursive = options.recursive;
var _options$columns = options.columns;
const columns = _options$columns === undefined ? [] : _options$columns,
checkOption = options.checkOption;
// prettier-ignore
var columnNames = (0, _utils.quote)(Array.isArray(columns) ? columns : [columns]).join(", ");
var replaceStr = replace ? " OR REPLACE" : "";
var temporaryStr = temporary ? " TEMPORARY" : "";
var recursiveStr = recursive ? " RECURSIVE" : "";
var columnStr = columnNames ? `(${columnNames})` : "";
var checkOptionStr = checkOption ? ` WITH ${checkOption} CHECK OPTION` : "";
const columnNames = (0, _utils.quote)(Array.isArray(columns) ? columns : [columns]).join(", ");
const replaceStr = replace ? " OR REPLACE" : "";
const temporaryStr = temporary ? " TEMPORARY" : "";
const recursiveStr = recursive ? " RECURSIVE" : "";
const columnStr = columnNames ? `(${columnNames})` : "";
const checkOptionStr = checkOption ? ` WITH ${checkOption} CHECK OPTION` : "";

@@ -40,6 +36,6 @@ return _utils.template`CREATE${replaceStr}${temporaryStr}${recursiveStr} VIEW "${viewName}"${columnStr} AS ${definition}${checkOptionStr};`;

var alterView = exports.alterView = function alterView(viewName, options) {
var checkOption = options.checkOption;
const alterView = exports.alterView = (viewName, options) => {
const checkOption = options.checkOption;
var clauses = [];
const clauses = [];
if (checkOption !== undefined) {

@@ -52,11 +48,9 @@ if (checkOption) {

}
return clauses.map(function (clause) {
return _utils.template`ALTER VIEW "${viewName}" ${clause};`;
}).join("\n");
return clauses.map(clause => _utils.template`ALTER VIEW "${viewName}" ${clause};`).join("\n");
};
var alterViewColumn = exports.alterViewColumn = function alterViewColumn(viewName, columnName, options) {
var defaultValue = options.default;
const alterViewColumn = exports.alterViewColumn = (viewName, columnName, options) => {
const defaultValue = options.default;
var actions = [];
const actions = [];
if (defaultValue === null) {

@@ -67,16 +61,10 @@ actions.push("DROP DEFAULT");

}
return actions.map(function (action) {
return _utils.template`ALTER VIEW "${viewName}" ALTER COLUMN ${columnName} ${action};`;
}).join("\n");
return actions.map(action => _utils.template`ALTER VIEW "${viewName}" ALTER COLUMN ${columnName} ${action};`).join("\n");
};
var renameView = exports.renameView = function renameView(viewName, newViewName) {
return _utils.template`ALTER VIEW "${viewName}" RENAME TO "${newViewName}";`;
};
const renameView = exports.renameView = (viewName, newViewName) => _utils.template`ALTER VIEW "${viewName}" RENAME TO "${newViewName}";`;
var undoRename = function undoRename(viewName, newViewName) {
return renameView(newViewName, viewName);
};
const undoRename = (viewName, newViewName) => renameView(newViewName, viewName);
createView.reverse = dropView;
renameView.reverse = undoRename;

@@ -10,40 +10,32 @@ "use strict";

var dataClause = function dataClause(data) {
return data !== undefined ? ` WITH${data ? "" : " NO"} DATA` : "";
const dataClause = data => data !== undefined ? ` WITH${data ? "" : " NO"} DATA` : "";
const storageParameterStr = storageParameters => key => {
const value = storageParameters[key] === true ? "" : ` = ${storageParameters[key]}`;
return `${key}${value}`;
};
var storageParameterStr = function storageParameterStr(storageParameters) {
return function (key) {
var value = storageParameters[key] === true ? "" : ` = ${storageParameters[key]}`;
return `${key}${value}`;
};
};
var dropMaterializedView = exports.dropMaterializedView = function dropMaterializedView(viewName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists,
cascade = _ref.cascade;
var ifExistsStr = ifExists ? " IF EXISTS" : "";
var cascadeStr = cascade ? " CASCADE" : "";
const dropMaterializedView = exports.dropMaterializedView = (viewName, { ifExists, cascade } = {}) => {
const ifExistsStr = ifExists ? " IF EXISTS" : "";
const cascadeStr = cascade ? " CASCADE" : "";
return _utils.template`DROP MATERIALIZED VIEW${ifExistsStr} "${viewName}"${cascadeStr};`;
};
var createMaterializedView = exports.createMaterializedView = function createMaterializedView(viewName, options, definition) {
var ifNotExists = options.ifNotExists,
_options$columns = options.columns,
columns = _options$columns === undefined ? [] : _options$columns,
tablespace = options.tablespace,
_options$storageParam = options.storageParameters,
storageParameters = _options$storageParam === undefined ? {} : _options$storageParam,
data = options.data;
const createMaterializedView = exports.createMaterializedView = (viewName, options, definition) => {
const ifNotExists = options.ifNotExists;
var _options$columns = options.columns;
const columns = _options$columns === undefined ? [] : _options$columns,
tablespace = options.tablespace;
var _options$storageParam = options.storageParameters;
const storageParameters = _options$storageParam === undefined ? {} : _options$storageParam,
data = options.data;
// prettier-ignore
var columnNames = (0, _utils.quote)(Array.isArray(columns) ? columns : [columns]).join(", ");
var withOptions = Object.keys(storageParameters).map(storageParameterStr(storageParameters)).join(", ");
const columnNames = (0, _utils.quote)(Array.isArray(columns) ? columns : [columns]).join(", ");
const withOptions = Object.keys(storageParameters).map(storageParameterStr(storageParameters)).join(", ");
var ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
var columnsStr = columnNames ? `(${columnNames})` : "";
var withOptionsStr = withOptions ? ` WITH (${withOptions})` : "";
var tablespaceStr = tablespace ? `TABLESPACE ${tablespace}` : "";
var dataStr = dataClause(data);
const ifNotExistsStr = ifNotExists ? " IF NOT EXISTS" : "";
const columnsStr = columnNames ? `(${columnNames})` : "";
const withOptionsStr = withOptions ? ` WITH (${withOptions})` : "";
const tablespaceStr = tablespace ? `TABLESPACE ${tablespace}` : "";
const dataStr = dataClause(data);

@@ -53,9 +45,9 @@ return _utils.template`CREATE MATERIALIZED VIEW${ifNotExistsStr} "${viewName}"${columnsStr}${withOptionsStr}${tablespaceStr} AS ${definition}${dataStr};`;

var alterMaterializedView = exports.alterMaterializedView = function alterMaterializedView(viewName, options) {
var cluster = options.cluster,
extension = options.extension,
_options$storageParam2 = options.storageParameters,
storageParameters = _options$storageParam2 === undefined ? {} : _options$storageParam2;
const alterMaterializedView = exports.alterMaterializedView = (viewName, options) => {
const cluster = options.cluster,
extension = options.extension;
var _options$storageParam2 = options.storageParameters;
const storageParameters = _options$storageParam2 === undefined ? {} : _options$storageParam2;
var clauses = [];
const clauses = [];
if (cluster !== undefined) {

@@ -71,41 +63,25 @@ if (cluster) {

}
var withOptions = Object.keys(storageParameters).filter(function (key) {
return storageParameters[key];
}).map(storageParameterStr(storageParameters)).join(", ");
const withOptions = Object.keys(storageParameters).filter(key => storageParameters[key]).map(storageParameterStr(storageParameters)).join(", ");
if (withOptions) {
clauses.push(`SET (${withOptions})`);
}
var resetOptions = Object.keys(storageParameters).filter(function (key) {
return !storageParameters[key];
}).join(", ");
const resetOptions = Object.keys(storageParameters).filter(key => !storageParameters[key]).join(", ");
if (resetOptions) {
clauses.push(`RESET (${resetOptions})`);
}
var clausesStr = (0, _utils.formatLines)(clauses);
const clausesStr = (0, _utils.formatLines)(clauses);
return _utils.template`ALTER MATERIALIZED VIEW "${viewName}"\n${clausesStr};`;
};
var renameMaterializedView = exports.renameMaterializedView = function renameMaterializedView(viewName, newViewName) {
return _utils.template`ALTER MATERIALIZED VIEW "${viewName}" RENAME TO "${newViewName}";`;
};
const renameMaterializedView = exports.renameMaterializedView = (viewName, newViewName) => _utils.template`ALTER MATERIALIZED VIEW "${viewName}" RENAME TO "${newViewName}";`;
var undoRename = function undoRename(viewName, newViewName) {
return renameMaterializedView(newViewName, viewName);
};
const undoRename = (viewName, newViewName) => renameMaterializedView(newViewName, viewName);
var renameMaterializedViewColumn = exports.renameMaterializedViewColumn = function renameMaterializedViewColumn(viewName, columnName, newColumnName) {
return _utils.template`ALTER MATERIALIZED VIEW "${viewName}" RENAME COLUMN ${columnName} TO "${newColumnName}";`;
};
const renameMaterializedViewColumn = exports.renameMaterializedViewColumn = (viewName, columnName, newColumnName) => _utils.template`ALTER MATERIALIZED VIEW "${viewName}" RENAME COLUMN ${columnName} TO "${newColumnName}";`;
var undoRenameColumn = function undoRenameColumn(viewName, columnName, newColumnName) {
return renameMaterializedViewColumn(viewName, newColumnName, columnName);
};
const undoRenameColumn = (viewName, columnName, newColumnName) => renameMaterializedViewColumn(viewName, newColumnName, columnName);
var refreshMaterializedView = exports.refreshMaterializedView = function refreshMaterializedView(viewName) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
concurrently = _ref2.concurrently,
data = _ref2.data;
var concurrentlyStr = concurrently ? " CONCURRENTLY" : "";
var dataStr = dataClause(data);
const refreshMaterializedView = exports.refreshMaterializedView = (viewName, { concurrently, data } = {}) => {
const concurrentlyStr = concurrently ? " CONCURRENTLY" : "";
const dataStr = dataClause(data);
return _utils.template`REFRESH MATERIALIZED VIEW${concurrentlyStr} "${viewName}"${dataStr};`;

@@ -112,0 +88,0 @@ };

@@ -8,4 +8,2 @@ "use strict";

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -40,82 +38,44 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
// Random but well-known identifier shared by all instances of node-pg-migrate
var PG_MIGRATE_LOCK_ID = 7241865325823964;
const PG_MIGRATE_LOCK_ID = 7241865325823964;
var readdir = function readdir() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
const readdir = (...args) => new Promise((resolve, reject) =>
// eslint-disable-next-line security/detect-non-literal-fs-filename
_fs2.default.readdir(...args, (err, files) => err ? reject(err) : resolve(files)));
const nameColumn = "name";
const runOnColumn = "run_on";
return new Promise(function (resolve, reject) {
return (
// eslint-disable-next-line security/detect-non-literal-fs-filename
_fs2.default.readdir.apply(_fs2.default, args.concat([function (err, files) {
return err ? reject(err) : resolve(files);
}]))
);
const loadMigrationFiles = (db, options, log) => readdir(`${options.dir}/`).then(files => Promise.all(files.map(file => new Promise((resolve, reject) =>
// eslint-disable-next-line security/detect-non-literal-fs-filename
_fs2.default.lstat(`${options.dir}/${file}`, (err, stats) => err ? reject(err) : resolve(stats.isFile() ? file : null)))))).then(files => {
const filter = new RegExp(`^(${options.ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
let shorthands = {};
return files.filter(i => i && !filter.test(i)).sort((f1, f2) => f1 < f2 // eslint-disable-line no-nested-ternary
? -1 : f1 > f2 ? 1 : 0).map(file => {
const filePath = `${options.dir}/${file}`;
const actions = _path2.default.extname(filePath) === ".sql" ? // eslint-disable-next-line security/detect-non-literal-fs-filename
{ up: pgm => pgm.sql(_fs2.default.readFileSync(filePath, "utf8")) } : // eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require
require(_path2.default.relative(__dirname, filePath));
shorthands = _extends({}, shorthands, actions.shorthands);
return new _migration2.default(db, filePath, actions, options, _extends({}, shorthands), log);
});
};
var nameColumn = "name";
var runOnColumn = "run_on";
}).catch(err => {
throw new Error(`Can't get migration files: ${err.stack}`);
});
var loadMigrationFiles = function loadMigrationFiles(db, options, log) {
return readdir(`${options.dir}/`).then(function (files) {
return Promise.all(files.map(function (file) {
return new Promise(function (resolve, reject) {
return (
// eslint-disable-next-line security/detect-non-literal-fs-filename
_fs2.default.lstat(`${options.dir}/${file}`, function (err, stats) {
return err ? reject(err) : resolve(stats.isFile() ? file : null);
})
);
});
}));
}).then(function (files) {
var filter = new RegExp(`^(${options.ignorePattern})$`); // eslint-disable-line security/detect-non-literal-regexp
var shorthands = {};
return files.filter(function (i) {
return i && !filter.test(i);
}).sort(function (f1, f2) {
return f1 < f2 // eslint-disable-line no-nested-ternary
? -1 : f1 > f2 ? 1 : 0;
}).map(function (file) {
var filePath = `${options.dir}/${file}`;
var actions = _path2.default.extname(filePath) === ".sql" ? // eslint-disable-next-line security/detect-non-literal-fs-filename
{ up: function up(pgm) {
return pgm.sql(_fs2.default.readFileSync(filePath, "utf8"));
} } : // eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require
require(_path2.default.relative(__dirname, filePath));
shorthands = _extends({}, shorthands, actions.shorthands);
return new _migration2.default(db, filePath, actions, options, _extends({}, shorthands), log);
});
}).catch(function (err) {
throw new Error(`Can't get migration files: ${err.stack}`);
});
};
const lock = db => db.query(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as lock_obtained`).then(result => {
if (!result.rows[0].lock_obtained) {
throw new Error("Another migration is already running");
}
});
var lock = function lock(db) {
return db.query(`select pg_try_advisory_lock(${PG_MIGRATE_LOCK_ID}) as lock_obtained`).then(function (result) {
if (!result.rows[0].lock_obtained) {
throw new Error("Another migration is already running");
}
});
};
const getRunMigrations = (db, options) => {
const schema = (0, _utils.getMigrationTableSchema)(options);
const migrationsTable = options.migrationsTable;
var getRunMigrations = function getRunMigrations(db, options) {
var schema = (0, _utils.getMigrationTableSchema)(options);
var migrationsTable = options.migrationsTable;
var fullTableName = {
const fullTableName = {
schema,
name: migrationsTable
};
return db.select(`SELECT table_name FROM information_schema.tables WHERE table_schema = '${schema}' AND table_name = '${migrationsTable}'`).then(function (migrationTables) {
return migrationTables && migrationTables.length === 1 || db.query(_utils.template`CREATE TABLE "${fullTableName}" ( id SERIAL, ${nameColumn} varchar(255) NOT NULL, ${runOnColumn} timestamp NOT NULL)`);
}).then(function () {
return !options.noLock ? lock(db, options) : null;
}).then(function () {
return db.column(_utils.template`SELECT ${nameColumn} FROM "${fullTableName}" ORDER BY ${runOnColumn}`, nameColumn);
}).catch(function (err) {
return db.select(`SELECT table_name FROM information_schema.tables WHERE table_schema = '${schema}' AND table_name = '${migrationsTable}'`).then(migrationTables => migrationTables && migrationTables.length === 1 || db.query(_utils.template`CREATE TABLE "${fullTableName}" ( id SERIAL, ${nameColumn} varchar(255) NOT NULL, ${runOnColumn} timestamp NOT NULL)`)).then(() => !options.noLock ? lock(db, options) : null).then(() => db.column(_utils.template`SELECT ${nameColumn} FROM "${fullTableName}" ORDER BY ${runOnColumn}`, nameColumn)).catch(err => {
throw new Error(`Unable to fetch migrations: ${err.stack}`);

@@ -125,21 +85,9 @@ });

var getMigrationsToRun = function getMigrationsToRun(options, runNames, migrations) {
const getMigrationsToRun = (options, runNames, migrations) => {
if (options.direction === "down") {
var downMigrations = runNames.filter(function (migrationName) {
return !options.file || options.file === migrationName;
}).map(function (migrationName) {
return migrations.find(function (_ref) {
var name = _ref.name;
return name === migrationName;
}) || migrationName;
});
var toRun = (options.timestamp ? downMigrations.filter(function (_ref2) {
var timestamp = _ref2.timestamp;
return timestamp >= options.count;
}) : downMigrations.slice(-Math.abs(options.count === undefined ? 1 : options.count))).reverse();
var deletedMigrations = toRun.filter(function (migration) {
return typeof migration === "string";
});
const downMigrations = runNames.filter(migrationName => !options.file || options.file === migrationName).map(migrationName => migrations.find(({ name }) => name === migrationName) || migrationName);
const toRun = (options.timestamp ? downMigrations.filter(({ timestamp }) => timestamp >= options.count) : downMigrations.slice(-Math.abs(options.count === undefined ? 1 : options.count))).reverse();
const deletedMigrations = toRun.filter(migration => typeof migration === "string");
if (deletedMigrations.length) {
var deletedMigrationsStr = deletedMigrations.join(", ");
const deletedMigrationsStr = deletedMigrations.join(", ");
throw new Error(`Definitions of migrations ${deletedMigrationsStr} have been deleted.`);

@@ -149,51 +97,29 @@ }

}
var upMigrations = migrations.filter(function (_ref3) {
var name = _ref3.name;
return runNames.indexOf(name) < 0 && (!options.file || options.file === name);
});
return options.timestamp ? upMigrations.filter(function (_ref4) {
var timestamp = _ref4.timestamp;
return timestamp <= options.count;
}) : upMigrations.slice(0, Math.abs(options.count === undefined ? Infinity : options.count));
const upMigrations = migrations.filter(({ name }) => runNames.indexOf(name) < 0 && (!options.file || options.file === name));
return options.timestamp ? upMigrations.filter(({ timestamp }) => timestamp <= options.count) : upMigrations.slice(0, Math.abs(options.count === undefined ? Infinity : options.count));
};
var ifSingleTransaction = function ifSingleTransaction(operation, options, db) {
return options.singleTransaction ? db.query(operation) : Promise.resolve();
};
const ifSingleTransaction = (operation, options, db) => options.singleTransaction ? db.query(operation) : Promise.resolve();
exports.default = function (options) {
var _Promise$resolve$then;
var log = options.log || console.log;
var db = (0, _db2.default)(options.databaseUrl);
return (_Promise$resolve$then = Promise.resolve().then(function () {
var promise = Promise.resolve();
exports.default = options => {
const log = options.log || console.log;
const db = (0, _db2.default)(options.databaseUrl);
return Promise.resolve().then(() => {
let promise = Promise.resolve();
if (options.schema) {
if (options.createSchema) {
promise = promise.then(function () {
return db.query(`CREATE SCHEMA IF NOT EXISTS "${options.schema}"`);
});
promise = promise.then(() => db.query(`CREATE SCHEMA IF NOT EXISTS "${options.schema}"`));
}
promise = promise.then(function () {
return db.query(`SET SCHEMA '${options.schema}'`);
});
promise = promise.then(() => db.query(`SET SCHEMA '${options.schema}'`));
}
if (options.migrationsSchema && options.createMigrationsSchema) {
promise = promise.then(function () {
return db.query(`CREATE SCHEMA IF NOT EXISTS "${options.migrationsSchema}"`);
});
promise = promise.then(() => db.query(`CREATE SCHEMA IF NOT EXISTS "${options.migrationsSchema}"`));
}
return promise;
}).then(function () {
return Promise.all([loadMigrationFiles(db, options, log), getRunMigrations(db, options)]);
}).then(function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
migrations = _ref6[0],
runNames = _ref6[1];
}).then(() => Promise.all([loadMigrationFiles(db, options, log), getRunMigrations(db, options)])).then(([migrations, runNames]) => {
if (options.checkOrder) {
var len = Math.min(runNames.length, migrations.length);
for (var i = 0; i < len; i += 1) {
var runName = runNames[i];
var migrationName = migrations[i].name;
const len = Math.min(runNames.length, migrations.length);
for (let i = 0; i < len; i += 1) {
const runName = runNames[i];
const migrationName = migrations[i].name;
if (runName !== migrationName) {

@@ -205,3 +131,3 @@ throw new Error(`Not run migration ${migrationName} is preceding already run migration ${runName}`);

var toRun = getMigrationsToRun(options, runNames, migrations);
const toRun = getMigrationsToRun(options, runNames, migrations);

@@ -215,23 +141,13 @@ if (!toRun.length) {

log("> Migrating files:");
toRun.forEach(function (m) {
toRun.forEach(m => {
log(`> - ${m.name}`);
});
return ifSingleTransaction("BEGIN", options, db).then(function () {
return toRun.reduce(function (promise, migration) {
return promise.then(function () {
return options.direction === "up" ? migration.applyUp() : migration.applyDown();
});
}, Promise.resolve());
}).then(function () {
return ifSingleTransaction("COMMIT", options, db);
});
}).catch(function (e) {
var _db$query;
return ifSingleTransaction("BEGIN", options, db).then(() => toRun.reduce((promise, migration) => promise.then(() => options.direction === "up" ? migration.applyUp() : migration.applyDown()), Promise.resolve())).then(() => ifSingleTransaction("COMMIT", options, db));
}).catch(e => {
log("> Rolling back attempted migration ...");
return (_db$query = db.query("ROLLBACK")).then.apply(_db$query, _toConsumableArray((0, _utils.finallyPromise)(function () {
return db.query("ROLLBACK").then(...(0, _utils.finallyPromise)(() => {
throw e;
})));
})).then.apply(_Promise$resolve$then, _toConsumableArray((0, _utils.finallyPromise)(db.close)));
}));
}).then(...(0, _utils.finallyPromise)(db.close));
};

@@ -9,36 +9,23 @@ "use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// This is used to create unescaped strings
// exposed in the migrations via pgm.func
var PgLiteral = exports.PgLiteral = function () {
_createClass(PgLiteral, null, [{
key: "create",
value: function create(str) {
return new PgLiteral(str);
}
}]);
class PgLiteral {
static create(str) {
return new PgLiteral(str);
}
function PgLiteral(str) {
_classCallCheck(this, PgLiteral);
constructor(str) {
this._str = str;
}
_createClass(PgLiteral, [{
key: "toString",
value: function toString() {
return this._str;
}
}]);
toString() {
return this._str;
}
}
return PgLiteral;
}();
var schemalize = exports.schemalize = function schemalize(v) {
exports.PgLiteral = PgLiteral;
const schemalize = exports.schemalize = v => {
if (typeof v === "object") {
var schema = v.schema,
name = v.name;
const schema = v.schema,
name = v.name;

@@ -50,6 +37,6 @@ return (schema ? `${schema}"."` : "") + name;

var opSchemalize = exports.opSchemalize = function opSchemalize(v) {
const opSchemalize = exports.opSchemalize = v => {
if (typeof v === "object") {
var schema = v.schema,
name = v.name;
const schema = v.schema,
name = v.name;

@@ -61,10 +48,6 @@ return schema ? `OPERATOR(${schema}.${name})` : name;

var t = exports.t = function t(s, d) {
return Object.keys(d || {}).reduce(function (str, p) {
return str.replace(new RegExp(`{${p}}`, "g"), schemalize(d[p]));
}, // eslint-disable-line security/detect-non-literal-regexp
s);
};
const t = exports.t = (s, d) => Object.keys(d || {}).reduce((str, p) => str.replace(new RegExp(`{${p}}`, "g"), schemalize(d[p])), // eslint-disable-line security/detect-non-literal-regexp
s);
var escapeValue = exports.escapeValue = function escapeValue(val) {
const escapeValue = exports.escapeValue = val => {
if (val === null) {

@@ -77,4 +60,4 @@ return "NULL";

if (typeof val === "string") {
var dollars = void 0;
var index = 0;
let dollars;
let index = 0;
do {

@@ -90,3 +73,3 @@ index += 1;

if (Array.isArray(val)) {
var arrayStr = val.map(escapeValue).join(",").replace(/ARRAY/g, "");
const arrayStr = val.map(escapeValue).join(",").replace(/ARRAY/g, "");
return `ARRAY[${arrayStr}]`;

@@ -100,9 +83,5 @@ }

var template = exports.template = function template(strings) {
for (var _len = arguments.length, keys = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
keys[_key - 1] = arguments[_key];
}
var result = [strings[0]];
keys.forEach(function (key, i) {
const template = exports.template = (strings, ...keys) => {
const result = [strings[0]];
keys.forEach((key, i) => {
result.push(schemalize(key), strings[i + 1]);

@@ -113,9 +92,5 @@ });

var opTemplate = exports.opTemplate = function opTemplate(strings) {
for (var _len2 = arguments.length, keys = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
keys[_key2 - 1] = arguments[_key2];
}
var result = [strings[0]];
keys.forEach(function (key, i) {
const opTemplate = exports.opTemplate = (strings, ...keys) => {
const result = [strings[0]];
keys.forEach((key, i) => {
result.push(opSchemalize(key), strings[i + 1]);

@@ -126,30 +101,22 @@ });

var getMigrationTableSchema = exports.getMigrationTableSchema = function getMigrationTableSchema(options) {
return options.migrationsSchema !== undefined // eslint-disable-line no-nested-ternary
? options.migrationsSchema : options.schema !== undefined ? options.schema : "public";
};
const getMigrationTableSchema = exports.getMigrationTableSchema = options => options.migrationsSchema !== undefined // eslint-disable-line no-nested-ternary
? options.migrationsSchema : options.schema !== undefined ? options.schema : "public";
var finallyPromise = exports.finallyPromise = function finallyPromise(func) {
return [func, function (err) {
var errHandler = function errHandler(innerErr) {
console.error(innerErr.stack ? innerErr.stack : innerErr);
const finallyPromise = exports.finallyPromise = func => [func, err => {
const errHandler = innerErr => {
console.error(innerErr.stack ? innerErr.stack : innerErr);
throw err;
};
try {
return Promise.resolve(func()).then(() => {
throw err;
};
try {
return Promise.resolve(func()).then(function () {
throw err;
}, errHandler);
} catch (innerErr) {
return errHandler(innerErr);
}
}];
};
}, errHandler);
} catch (innerErr) {
return errHandler(innerErr);
}
}];
var quote = exports.quote = function quote(array) {
return array.map(function (item) {
return template`"${item}"`;
});
};
const quote = exports.quote = array => array.map(item => template`"${item}"`);
var typeAdapters = {
const typeAdapters = {
int: "integer",

@@ -163,3 +130,3 @@ string: "text",

var defaultTypeShorthands = {
const defaultTypeShorthands = {
id: { type: "serial", primaryKey: true // convenience type for serial primary keys

@@ -169,12 +136,8 @@ } };

// some convenience adapters -- see above
var applyTypeAdapters = exports.applyTypeAdapters = function applyTypeAdapters(type) {
return typeAdapters[type] ? typeAdapters[type] : type;
};
const applyTypeAdapters = exports.applyTypeAdapters = type => typeAdapters[type] ? typeAdapters[type] : type;
var applyType = exports.applyType = function applyType(type) {
var extendingTypeShorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var typeShorthands = _extends({}, defaultTypeShorthands, extendingTypeShorthands);
var options = typeof type === "string" ? { type } : type;
var ext = typeShorthands[options.type] || { type: options.type };
const applyType = exports.applyType = (type, extendingTypeShorthands = {}) => {
const typeShorthands = _extends({}, defaultTypeShorthands, extendingTypeShorthands);
const options = typeof type === "string" ? { type } : type;
const ext = typeShorthands[options.type] || { type: options.type };
return _extends({}, ext, options, {

@@ -185,6 +148,6 @@ type: applyTypeAdapters(ext.type)

var formatParam = function formatParam(typeShorthands) {
return function (param) {
var _applyType = applyType(param, typeShorthands),
mode = _applyType.mode,
const formatParam = typeShorthands => param => {
var _applyType = applyType(param, typeShorthands);
const mode = _applyType.mode,
name = _applyType.name,

@@ -194,36 +157,25 @@ type = _applyType.type,

var options = [];
if (mode) {
options.push(mode);
}
if (name) {
options.push(schemalize(name));
}
if (type) {
options.push(type);
}
if (defaultValue) {
options.push(`DEFAULT ${escapeValue(defaultValue)}`);
}
return options.join(" ");
};
const options = [];
if (mode) {
options.push(mode);
}
if (name) {
options.push(schemalize(name));
}
if (type) {
options.push(type);
}
if (defaultValue) {
options.push(`DEFAULT ${escapeValue(defaultValue)}`);
}
return options.join(" ");
};
var formatParams = exports.formatParams = function formatParams() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var typeShorthands = arguments[1];
return `(${params.map(formatParam(typeShorthands)).join(", ")})`;
};
const formatParams = exports.formatParams = (params = [], typeShorthands) => `(${params.map(formatParam(typeShorthands)).join(", ")})`;
var comment = exports.comment = function comment(object, name, text) {
var cmt = escapeValue(text || null);
const comment = exports.comment = (object, name, text) => {
const cmt = escapeValue(text || null);
return template`COMMENT ON ${object} "${name}" IS ${cmt};`;
};
var formatLines = exports.formatLines = function formatLines(lines) {
var replace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : " ";
var separator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ",";
return lines.map(function (line) {
return line.replace(/(?:\r\n|\r|\n)+/g, " ");
}).join(`${separator}\n`).replace(/^/gm, replace);
};
const formatLines = exports.formatLines = (lines, replace = " ", separator = ",") => lines.map(line => line.replace(/(?:\r\n|\r|\n)+/g, " ")).join(`${separator}\n`).replace(/^/gm, replace);

@@ -6,18 +6,18 @@ # Programmatic API

* `databaseUrl` _[string or object]_ - Connection string or client config which is passed to [new pg.Client](https://node-postgres.com/api/client#new-client-config-object-)
* `migrationsTable` _[string]_ - The table storing which migrations have been run
* `migrationsSchema` _[string]_ - The schema storing table which migrations have been run (defaults to same value as `schema`)
* `schema` _[string]_ - The schema on which migration will be run (defaults to `public`)
* `dir` _[string]_ - The directory containing your migration files
* `checkOrder` _[boolean]_ - Check order of migrations before running them
* `direction` _[enum]_ - `up` or `down`
* `count` _[number]_ - Number of migration to run
* `timestamp` _[boolean]_ - Treats `count` as timestamp
* `ignorePattern` _[string]_ - Regex pattern for file names to ignore
* `file` _[string]_ - Run only migration with this name
* `singleTransaction` _[boolean]_ - Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back (defaults to `true`)
* `createSchema` _[boolean]_ - Creates the configured schema if it doesn't exist
* `createMigrationsSchema` _[boolean]_ - Creates the configured migration schema if it doesn't exist
* `noLock` _[boolean]_ - Disables locking mechanism and checks
* `dryRun` _[boolean]_
* `log` _[function]_ - Redirect log messages to this function, rather than `console.log`
- `databaseUrl` _[string or object]_ - Connection string or client config which is passed to [new pg.Client](https://node-postgres.com/api/client#new-client-config-object-)
- `migrationsTable` _[string]_ - The table storing which migrations have been run
- `migrationsSchema` _[string]_ - The schema storing table which migrations have been run (defaults to same value as `schema`)
- `schema` _[string]_ - The schema on which migration will be run (defaults to `public`)
- `dir` _[string]_ - The directory containing your migration files
- `checkOrder` _[boolean]_ - Check order of migrations before running them
- `direction` _[enum]_ - `up` or `down`
- `count` _[number]_ - Number of migration to run
- `timestamp` _[boolean]_ - Treats `count` as timestamp
- `ignorePattern` _[string]_ - Regex pattern for file names to ignore
- `file` _[string]_ - Run only migration with this name
- `singleTransaction` _[boolean]_ - Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back (defaults to `true`)
- `createSchema` _[boolean]_ - Creates the configured schema if it doesn't exist
- `createMigrationsSchema` _[boolean]_ - Creates the configured migration schema if it doesn't exist
- `noLock` _[boolean]_ - Disables locking mechanism and checks
- `dryRun` _[boolean]_
- `log` _[function]_ - Redirect log messages to this function, rather than `console.log`

@@ -52,9 +52,9 @@ # CLI Usage

* `node-pg-migrate create {migration-name}` - creates a new migration file with the name you give it. Spaces and underscores will be replaced by dashes and a timestamp is prepended to your file name.
* `node-pg-migrate up` - runs all up migrations from the current state.
* `node-pg-migrate up {N}` - runs N up migrations from the current state.
* `node-pg-migrate down` - runs a single down migration.
* `node-pg-migrate down {N}` - runs N down migrations from the current state.
* `node-pg-migrate redo` - redoes last migration (runs a single down migration, then single up migration).
* `node-pg-migrate redo {N}` - redoes N last migrations (runs N down migrations, then N up migrations).
- `node-pg-migrate create {migration-name}` - creates a new migration file with the name you give it. Spaces and underscores will be replaced by dashes and a timestamp is prepended to your file name.
- `node-pg-migrate up` - runs all up migrations from the current state.
- `node-pg-migrate up {N}` - runs N up migrations from the current state.
- `node-pg-migrate down` - runs a single down migration.
- `node-pg-migrate down {N}` - runs N down migrations from the current state.
- `node-pg-migrate redo` - redoes last migration (runs a single down migration, then single up migration).
- `node-pg-migrate redo {N}` - redoes N last migrations (runs N down migrations, then N up migrations).

@@ -65,17 +65,17 @@ ## Configuration

* `config-file` (`f`) - The file with migration JSON config (defaults to undefined)
* `schema` (`s`) - The schema on which migration will be run (defaults to `public`)
* `create-schema` - Create the configured schema if it doesn't exist (defaults to `false`)
* `database-url-var` (`d`) - Name of env variable with database url string (defaults to `DATABASE_URL`)
* `migrations-dir` (`m`) - The directory containing your migration files (defaults to `migrations`)
* `migrations-schema` - The schema storing table which migrations have been run (defaults to same value as `schema`)
* `create-migrations-schema` - Create the configured migrations schema if it doesn't exist (defaults to `false`)
* `migrations-table` (`t`) - The table storing which migrations have been run (defaults to `pgmigrations`)
* `ignore-pattern` - Regex pattern for file names to ignore (e.g. `ignore_file|\..*|.*\.spec\.js`)
* `migration-file-language` (`j`) - Language of the migration file to create (`js` or `ts`)
* `timestamp` - Treats number argument to up/down migration as timestamp (running up migrations less or equal to timestamp or down migrations greater or equal to timestamp)
* `check-order` - Check order of migrations before running them (defaults to `true`, to switch it off supply `--no-check-order` on command line).
- `config-file` (`f`) - The file with migration JSON config (defaults to undefined)
- `schema` (`s`) - The schema on which migration will be run (defaults to `public`)
- `create-schema` - Create the configured schema if it doesn't exist (defaults to `false`)
- `database-url-var` (`d`) - Name of env variable with database url string (defaults to `DATABASE_URL`)
- `migrations-dir` (`m`) - The directory containing your migration files (defaults to `migrations`)
- `migrations-schema` - The schema storing table which migrations have been run (defaults to same value as `schema`)
- `create-migrations-schema` - Create the configured migrations schema if it doesn't exist (defaults to `false`)
- `migrations-table` (`t`) - The table storing which migrations have been run (defaults to `pgmigrations`)
- `ignore-pattern` - Regex pattern for file names to ignore (e.g. `ignore_file|\..*|.*\.spec\.js`)
- `migration-file-language` (`j`) - Language of the migration file to create (`js` or `ts`)
- `timestamp` - Treats number argument to up/down migration as timestamp (running up migrations less or equal to timestamp or down migrations greater or equal to timestamp)
- `check-order` - Check order of migrations before running them (defaults to `true`, to switch it off supply `--no-check-order` on command line).
(There should be no migration with timestamp lesser than last run migration.)
* `single-transaction` - Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back (defaults to `true`, to switch it off supply `--no-single-transaction` on command line).
* `no-lock` - Disables locking mechanism and checks (useful for DBs which does not support SQL commands used for [locking](migrations.md#locking))
- `single-transaction` - Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back (defaults to `true`, to switch it off supply `--no-single-transaction` on command line).
- `no-lock` - Disables locking mechanism and checks (useful for DBs which does not support SQL commands used for [locking](migrations.md#locking))

@@ -95,3 +95,3 @@ See all by running `node-pg-migrate --help`.

* `migrations-dir`, `migrations-schema`, `migrations-table`, `check-order`, `ignore-pattern` - same as above
* either `url` or [`user`], [`password`], `host` (defaults to localhost), `port` (defaults to 5432), `database` - for connection details
- `migrations-dir`, `migrations-schema`, `migrations-table`, `check-order`, `ignore-pattern` - same as above
- either `url` or [`user`], [`password`], `host` (defaults to localhost), `port` (defaults to 5432), `database` - for connection details

@@ -7,16 +7,16 @@ # Column Operations

* `type` _[string]_ - data type (use normal postgres types)
* `collation` _[string]_ - collation of data type
* `unique` _[boolean]_ - set to true to add a unique constraint on this column
* `primaryKey` _[boolean]_ - set to true to make this column the primary key
* `notNull` _[boolean]_ - set to true to make this column not null
* `default` _[string]_ - adds DEFAULT clause for column. Accepts null, a literal value, or a `pgm.func()` expression.
* `check` _[string]_ - sql for a check constraint for this column
* `references` _[string]_ - a table name that this column is a foreign key to
* `onDelete` _[string]_ - adds ON DELETE constraint for a reference column
* `onUpdate` _[string]_ - adds ON UPDATE constraint for a reference column
* `match` _[string]_ - `FULL` or `SIMPLE`
* `deferrable` _[boolean]_ - flag for deferrable column constraint
* `deferred` _[boolean]_ - flag for initially deferred deferrable column constraint
* `comment` _[string]_ - adds comment on column
- `type` _[string]_ - data type (use normal postgres types)
- `collation` _[string]_ - collation of data type
- `unique` _[boolean]_ - set to true to add a unique constraint on this column
- `primaryKey` _[boolean]_ - set to true to make this column the primary key
- `notNull` _[boolean]_ - set to true to make this column not null
- `default` _[string]_ - adds DEFAULT clause for column. Accepts null, a literal value, or a `pgm.func()` expression.
- `check` _[string]_ - sql for a check constraint for this column
- `references` _[string]_ - a table name that this column is a foreign key to
- `onDelete` _[string]_ - adds ON DELETE constraint for a reference column
- `onUpdate` _[string]_ - adds ON UPDATE constraint for a reference column
- `match` _[string]_ - `FULL` or `SIMPLE`
- `deferrable` _[boolean]_ - flag for deferrable column constraint
- `deferred` _[boolean]_ - flag for initially deferred deferrable column constraint
- `comment` _[string]_ - adds comment on column

@@ -48,4 +48,4 @@ ## Data types & Convenience Shorthand

* `tablename` _[string]_ - name of the table to alter
* `new_columns` _[object]_ - column names / options -- see [column definitions section](#column-definitions)
- `tablename` _[string]_ - name of the table to alter
- `new_columns` _[object]_ - column names / options -- see [column definitions section](#column-definitions)

@@ -63,7 +63,7 @@ **Aliases:** `addColumn`

* `tablename` _[string]_ - name of the table to alter
* `columns` _[array of strings or object]_ - columns to drop (if object, uses keys)
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops column only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `tablename` _[string]_ - name of the table to alter
- `columns` _[array of strings or object]_ - columns to drop (if object, uses keys)
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops column only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -80,5 +80,5 @@ **Aliases:** `dropColumn`

* `tablename` _[string]_ - name of the table to alter
* `old_column_name` _[string]_ - current column name
* `new_column_name` _[string]_ - new column name
- `tablename` _[string]_ - name of the table to alter
- `old_column_name` _[string]_ - current column name
- `new_column_name` _[string]_ - new column name

@@ -95,11 +95,11 @@ **Reverse Operation:** same operation in opposite direction

* `tablename` _[string]_ - name of the table to alter
* `column_name` _[string]_ - column to alter
* `column_options` _[object]_ - optional new column options
* `default` _[string or null]_ - null, string
* `type` _[string]_ - new datatype
* `notNull` _[boolean]_ - sets NOT NULL if true or NULL if false
* `allowNull` _[boolean]_ - sets NULL if true (alternative to `notNull`)
* `using` _[string]_ - adds USING clause to change values in column
* `collation` _[string]_ - adds COLLATE clause to change values in column
* `comment` _[string]_ - adds comment on column
- `tablename` _[string]_ - name of the table to alter
- `column_name` _[string]_ - column to alter
- `column_options` _[object]_ - optional new column options
- `default` _[string or null]_ - null, string
- `type` _[string]_ - new datatype
- `notNull` _[boolean]_ - sets NOT NULL if true or NULL if false
- `allowNull` _[boolean]_ - sets NULL if true (alternative to `notNull`)
- `using` _[string]_ - adds USING clause to change values in column
- `collation` _[string]_ - adds COLLATE clause to change values in column
- `comment` _[string]_ - adds comment on column

@@ -9,17 +9,17 @@ # Constraint Operations

* `tablename` _[string]_ - name of the table to alter
* `constraint_name` _[string]_ - name for the constraint
* `expression` _[string or object]_ - constraint expression (raw sql) or definition:
* `check` _[string]_ - sql for a check constraint
* `unique` _[string or array of strings or array of array of strings]_ - names of unique columns
* `primaryKey` _[string or array of strings]_ - names of primary columns
* `exclude` _[string]_ - sql for an exclude constraint
* `deferrable` _[boolean]_ - flag for deferrable table constraint
* `deferred` _[boolean]_ - flag for initially deferred deferrable table constraint
* `foreignKeys` _[object or array of objects]_ - foreign keys specification
* `columns` _[string or array of strings]_ - names of columns
* `references` _[string]_ - names of foreign table and column names
* `onDelete` _[string]_ - action to perform on delete
* `onUpdate` _[string]_ - action to perform on update
* `match` _[string]_ - `FULL` or `SIMPLE`
- `tablename` _[string]_ - name of the table to alter
- `constraint_name` _[string]_ - name for the constraint
- `expression` _[string or object]_ - constraint expression (raw sql) or definition:
- `check` _[string]_ - sql for a check constraint
- `unique` _[string or array of strings or array of array of strings]_ - names of unique columns
- `primaryKey` _[string or array of strings]_ - names of primary columns
- `exclude` _[string]_ - sql for an exclude constraint
- `deferrable` _[boolean]_ - flag for deferrable table constraint
- `deferred` _[boolean]_ - flag for initially deferred deferrable table constraint
- `foreignKeys` _[object or array of objects]_ - foreign keys specification
- `columns` _[string or array of strings]_ - names of columns
- `references` _[string]_ - names of foreign table and column names
- `onDelete` _[string]_ - action to perform on delete
- `onUpdate` _[string]_ - action to perform on update
- `match` _[string]_ - `FULL` or `SIMPLE`

@@ -37,7 +37,7 @@ **Aliases:** `createConstraint`

* `tablename` _[string]_ - name of the table to alter
* `constraint_name` _[string]_ - name for the constraint
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops constraint only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `tablename` _[string]_ - name of the table to alter
- `constraint_name` _[string]_ - name for the constraint
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops constraint only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -52,6 +52,6 @@ ### `pgm.renameConstraint( tablename, old_constraint_name, new_constraint_name )`

* `tablename` _[string]_ - name of the table to alter
* `old_constraint_name` _[string]_ - current constraint name
* `new_constraint_name` _[string]_ - new constraint name
- `tablename` _[string]_ - name of the table to alter
- `old_constraint_name` _[string]_ - current constraint name
- `new_constraint_name` _[string]_ - new constraint name
**Reverse Operation:** same operation in opposite direction

@@ -9,10 +9,10 @@ # Domain Operations

* `domain_name` _[string]_ - name of the new domain
* `type` _[string]_ - type of the new domain
* `options` _[object]_ - options:
* `default` _[string]_ - default value of domain
* `collation` _[string]_ - collation of data type
* `notNull` _[boolean]_ - sets NOT NULL if true ([not recommended](https://www.postgresql.org/docs/10/static/sql-createdomain.html#idm46428678330368))
* `check` _[string]_ - sql for a check constraint for this column
* `constraintName` _[string]_ - name for constraint
- `domain_name` _[string]_ - name of the new domain
- `type` _[string]_ - type of the new domain
- `options` _[object]_ - options:
- `default` _[string]_ - default value of domain
- `collation` _[string]_ - collation of data type
- `notNull` _[boolean]_ - sets NOT NULL if true ([not recommended](https://www.postgresql.org/docs/10/static/sql-createdomain.html#idm46428678330368))
- `check` _[string]_ - sql for a check constraint for this column
- `constraintName` _[string]_ - name for constraint

@@ -29,6 +29,6 @@ **Reverse Operation:** `dropDomain`

* `domain_name` _[string]_ - name of the the domain to drop
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops domain only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `domain_name` _[string]_ - name of the the domain to drop
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops domain only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -43,10 +43,10 @@ ---

* `domain_name` _[string]_ - name of the new domain
* `options` _[object]_ - options:
* `default` _[string]_ - default value of domain
* `collation` _[string]_ - collation of data type
* `notNull` _[boolean]_ - sets NOT NULL if true or NULL if false
* `allowNull` _[boolean]_ - sets NULL if true (alternative to `notNull`)
* `check` _[string]_ - sql for a check constraint for this column
* `constraintName` _[string]_ - name for constraint
- `domain_name` _[string]_ - name of the new domain
- `options` _[object]_ - options:
- `default` _[string]_ - default value of domain
- `collation` _[string]_ - collation of data type
- `notNull` _[boolean]_ - sets NOT NULL if true or NULL if false
- `allowNull` _[boolean]_ - sets NULL if true (alternative to `notNull`)
- `check` _[string]_ - sql for a check constraint for this column
- `constraintName` _[string]_ - name for constraint

@@ -61,3 +61,3 @@ ---

* `old_domain_name` _[string]_ - old name of the domain
* `new_domain_name` _[string]_ - new name of the domain
- `old_domain_name` _[string]_ - old name of the domain
- `new_domain_name` _[string]_ - new name of the domain

@@ -9,6 +9,6 @@ # Extension Operations

* `extension` _[string or array of strings]_ - name(s) of extensions to install
* `options` _[object]_ - options:
* `ifNotExists` _[boolean]_ - default `false`
* `schema` _[string]_ - the name of the schema in which to install the extension's objects
- `extension` _[string or array of strings]_ - name(s) of extensions to install
- `options` _[object]_ - options:
- `ifNotExists` _[boolean]_ - default `false`
- `schema` _[string]_ - the name of the schema in which to install the extension's objects

@@ -26,5 +26,5 @@ **Aliases:** `addExtension`

* `extension` _[string or array of strings]_ - name(s) of extensions to install
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops extension only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `extension` _[string or array of strings]_ - name(s) of extensions to install
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops extension only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -9,4 +9,4 @@ # Function Operations

* `function_name` _[string]_ - name of the new function
* `function_params` _[array]_ - parameters of the new function
- `function_name` _[string]_ - name of the new function
- `function_params` _[array]_ - parameters of the new function

@@ -16,16 +16,16 @@ Either array of strings or objects.

* `mode` _[string]_ - `IN`, `OUT`, `INOUT`, or `VARIADIC`
* `name` _[string]_ - name of argument
* `type` _[string]_ - datatype of argument
* `default` _[string]_ - default value of argument
- `mode` _[string]_ - `IN`, `OUT`, `INOUT`, or `VARIADIC`
- `name` _[string]_ - name of argument
- `type` _[string]_ - datatype of argument
- `default` _[string]_ - default value of argument
* `function_options` _[object]_ - options:
* `returns` _[string]_ - returns clause
* `language` _[string]_ - language name of function definition
* `replace` _[boolean]_ - create or replace function
* `window` _[boolean]_ - window function
* `behavior` _[string]_ - `IMMUTABLE`, `STABLE`, or `VOLATILE`
* `onNull` _[boolean]_ - `RETURNS NULL ON NULL INPUT`
* `parallel` _[string]_ - `UNSAFE`, `RESTRICTED`, or `SAFE`
* `definition` _[string]_ - definition of function
- `function_options` _[object]_ - options:
- `returns` _[string]_ - returns clause
- `language` _[string]_ - language name of function definition
- `replace` _[boolean]_ - create or replace function
- `window` _[boolean]_ - window function
- `behavior` _[string]_ - `IMMUTABLE`, `STABLE`, or `VOLATILE`
- `onNull` _[boolean]_ - `RETURNS NULL ON NULL INPUT`
- `parallel` _[string]_ - `UNSAFE`, `RESTRICTED`, or `SAFE`
- `definition` _[string]_ - definition of function

@@ -42,7 +42,7 @@ **Reverse Operation:** `dropFunction`

* `function_name` _[string]_ - name of the function to drop
* `function_params` _[array]_ - [see](#pgmcreatefunction-function_name-function_params-function_options-definition-)
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops function only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `function_name` _[string]_ - name of the function to drop
- `function_params` _[array]_ - [see](#pgmcreatefunction-function_name-function_params-function_options-definition-)
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops function only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -57,4 +57,4 @@ ---

* `old_function_name` _[string]_ - old name of the function
* `function_params` _[array]_ - [see](#pgmcreatefunction-function_name-function_params-function_options-definition-)
* `new_function_name` _[string]_ - new name of the function
- `old_function_name` _[string]_ - old name of the function
- `function_params` _[array]_ - [see](#pgmcreatefunction-function_name-function_params-function_options-definition-)
- `new_function_name` _[string]_ - new name of the function

@@ -9,11 +9,11 @@ # Index Operations

* `tablename` _[string]_ - name of the table to alter
* `columns` _[string or array of strings]_ - columns to add to the index
* `options` _[index options]_ - optional options:
* `name` _[string]_ - name for the index (one will be inferred from table/columns if undefined)
* `unique` _[boolean]_ - set to true if this is a unique index
* `where` _[string]_ - raw sql for where clause of index
* `concurrently` _[boolean]_ - create this index concurrently
* `opclass` _[string]_ - name of an operator class to use
* `method` _[string]_ - btree | hash | gist | spgist | gin
- `tablename` _[string]_ - name of the table to alter
- `columns` _[string or array of strings]_ - columns to add to the index
- `options` _[index options]_ - optional options:
- `name` _[string]_ - name for the index (one will be inferred from table/columns if undefined)
- `unique` _[boolean]_ - set to true if this is a unique index
- `where` _[string]_ - raw sql for where clause of index
- `concurrently` _[boolean]_ - create this index concurrently
- `opclass` _[string]_ - name of an operator class to use
- `method` _[string]_ - btree | hash | gist | spgist | gin

@@ -31,5 +31,5 @@ **Aliases:** `addIndex`

* `tablename` _[string]_ - name of the table to alter
* `columns` _[string or array of strings]_ - column names, used only to infer an index name
* `options` _[index options]_ - optional options:
* `name` _[string]_ - name of the index to drop
- `tablename` _[string]_ - name of the table to alter
- `columns` _[string or array of strings]_ - column names, used only to infer an index name
- `options` _[index options]_ - optional options:
- `name` _[string]_ - name of the index to drop

@@ -80,18 +80,18 @@ # Defining Migrations

* [Tables](tables.md)
* [Columns](columns.md)
* [Constraints](constraints.md)
* [Indexes](indexes.md)
* [Functions](functions.md)
* [Triggers](triggers.md)
* [Schemas](schemas.md)
* [Sequences](sequences.md)
* [Views](views.md)
* [Materialized Views](mViews.md)
* [Types](types.md)
* [Domains](domains.md)
* [Operators](operators.md)
* [Roles](roles.md)
* [Policies](policies.md)
* [Extensions](extensions.md)
* [Miscellaneous](misc.md)
- [Tables](tables.md)
- [Columns](columns.md)
- [Constraints](constraints.md)
- [Indexes](indexes.md)
- [Functions](functions.md)
- [Triggers](triggers.md)
- [Schemas](schemas.md)
- [Sequences](sequences.md)
- [Views](views.md)
- [Materialized Views](mViews.md)
- [Types](types.md)
- [Domains](domains.md)
- [Operators](operators.md)
- [Roles](roles.md)
- [Policies](policies.md)
- [Extensions](extensions.md)
- [Miscellaneous](misc.md)

@@ -9,4 +9,4 @@ # Miscellaneous Operations

* `sql` _[string]_ - SQL query to run
* `args` _[object]_ - (optional) key/val of arguments to replace
- `sql` _[string]_ - SQL query to run
- `args` _[object]_ - (optional) key/val of arguments to replace

@@ -23,3 +23,3 @@ ---

* `sql` _[string]_ - string to not be escaped
- `sql` _[string]_ - string to not be escaped

@@ -26,0 +26,0 @@ ---

@@ -9,10 +9,10 @@ # Materialized View Operations

* `viewName` _[string]_ - name of the new materialized view
* `options` _[object]_ - options:
* `ifNotExists` _[boolean]_ - default false
* `columns` _[string or array]_ - use if you want to name columns differently then inferred from definition
* `tablespace` _[string]_
* `storageParameters` _[object]_ - key value pairs of [Storage Parameters](https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS)
* `data` _[boolean]_ - default undefined
* `definition` _[string]_ - SQL of SELECT statement
- `viewName` _[string]_ - name of the new materialized view
- `options` _[object]_ - options:
- `ifNotExists` _[boolean]_ - default false
- `columns` _[string or array]_ - use if you want to name columns differently then inferred from definition
- `tablespace` _[string]_
- `storageParameters` _[object]_ - key value pairs of [Storage Parameters](https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS)
- `data` _[boolean]_ - default undefined
- `definition` _[string]_ - SQL of SELECT statement

@@ -29,6 +29,6 @@ **Reverse Operation:** `dropMaterializedView`

* `viewName` _[string]_ - name of the view to delete
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops view only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `viewName` _[string]_ - name of the view to delete
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops view only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -43,7 +43,7 @@ ---

* `viewName` _[string]_ - name of the view to alter
* `options` _[object]_ - options:
* `cluster` _[string]_ - index name for clustering
* `extension` _[string]_ - name of extension view is dependent on
* `storageParameters` _[object]_ - key value pairs of [Storage Parameters](https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS)
- `viewName` _[string]_ - name of the view to alter
- `options` _[object]_ - options:
- `cluster` _[string]_ - index name for clustering
- `extension` _[string]_ - name of extension view is dependent on
- `storageParameters` _[object]_ - key value pairs of [Storage Parameters](https://www.postgresql.org/docs/current/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS)

@@ -58,4 +58,4 @@ ---

* `viewName` _[string]_ - old name of the view
* `newViewName` _[string]_ - new name of the view
- `viewName` _[string]_ - old name of the view
- `newViewName` _[string]_ - new name of the view

@@ -70,5 +70,5 @@ ---

* `viewName` _[string]_ - name of the view to alter
* `columnName` _[string]_ - current column name
* `newColumnName` _[string]_ - new column name
- `viewName` _[string]_ - name of the view to alter
- `columnName` _[string]_ - current column name
- `newColumnName` _[string]_ - new column name

@@ -83,5 +83,5 @@ ---

* `viewName` _[string]_ - old name of the view
* `options` _[object]_ - options:
* `concurrently` _[boolean]_ - default false
* `data` _[boolean]_ - default undefined
- `viewName` _[string]_ - old name of the view
- `options` _[object]_ - options:
- `concurrently` _[boolean]_ - default false
- `data` _[boolean]_ - default undefined

@@ -9,13 +9,13 @@ # Operator Operations

* `operator_name` _[string]_ - name of the new operator
* `options` _[object]_ - options:
* `procedure` _[string]_ - name of procedure performing operation
* `left` _[string]_ - type of left argument
* `right` _[string]_ - type of right argument
* `commutator` _[string]_ - name of commutative operator
* `negator` _[string]_ - name of negating operator
* `restrict` _[string]_ - name of restriction procedure
* `join` _[string]_ - name of join procedure
* `hashes` _[boolean]_ - adds `HASHES` clause
* `merges` _[boolean]_ - adds `MERGES` clause
- `operator_name` _[string]_ - name of the new operator
- `options` _[object]_ - options:
- `procedure` _[string]_ - name of procedure performing operation
- `left` _[string]_ - type of left argument
- `right` _[string]_ - type of right argument
- `commutator` _[string]_ - name of commutative operator
- `negator` _[string]_ - name of negating operator
- `restrict` _[string]_ - name of restriction procedure
- `join` _[string]_ - name of join procedure
- `hashes` _[boolean]_ - adds `HASHES` clause
- `merges` _[boolean]_ - adds `MERGES` clause

@@ -32,8 +32,8 @@ **Reverse Operation:** `dropOperator`

* `operator_name` _[string]_ - name of the operator to drop
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops schema only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
* `left` _[string]_ - type of left argument
* `right` _[string]_ - type of right argument
- `operator_name` _[string]_ - name of the operator to drop
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops schema only if it exists
- `cascade` _[boolean]_ - drops also dependent objects
- `left` _[string]_ - type of left argument
- `right` _[string]_ - type of right argument

@@ -48,9 +48,9 @@ ---

* `operator_class_name` _[string]_ - name of the new operator class
* `type` _[string]_ - data type of the new operator class
* `index_method` _[string]_ - name of the index method of operator class
* `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)
* `options` _[object]_ - options:
* `default` _[boolean]_ - adds `DEFAULT` clause
* `family` _[string]_ - type of left argument
- `operator_class_name` _[string]_ - name of the new operator class
- `type` _[string]_ - data type of the new operator class
- `index_method` _[string]_ - name of the index method of operator class
- `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)
- `options` _[object]_ - options:
- `default` _[boolean]_ - adds `DEFAULT` clause
- `family` _[string]_ - type of left argument

@@ -67,7 +67,7 @@ **Reverse Operation:** `dropOperatorClass`

* `operator_class_name` _[string]_ - name of the operator class to drop
* `index_method` _[string]_ - name of the index method of operator class
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops schema only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `operator_class_name` _[string]_ - name of the operator class to drop
- `index_method` _[string]_ - name of the index method of operator class
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops schema only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -82,5 +82,5 @@ ---

* `old_operator_class_name` _[string]_ - old name of the operator class
* `index_method` _[string]_ - name of the index method of operator class
* `new_operator_class_name` _[string]_ - new name of the operator class
- `old_operator_class_name` _[string]_ - old name of the operator class
- `index_method` _[string]_ - name of the index method of operator class
- `new_operator_class_name` _[string]_ - new name of the operator class

@@ -95,4 +95,4 @@ ---

* `operator_family_name` _[string]_ - name of the new operator family
* `index_method` _[string]_ - name of the index method of operator family
- `operator_family_name` _[string]_ - name of the new operator family
- `index_method` _[string]_ - name of the index method of operator family

@@ -109,7 +109,7 @@ **Reverse Operation:** `dropOperatorFamily`

* `operator_family_name` _[string]_ - name of the operator family to drop
* `index_method` _[string]_ - name of the index method of operator family
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops schema only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `operator_family_name` _[string]_ - name of the operator family to drop
- `index_method` _[string]_ - name of the index method of operator family
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops schema only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -124,5 +124,5 @@ ---

* `old_operator_family_name` _[string]_ - old name of the operator family
* `index_method` _[string]_ - name of the index method of operator family
* `new_operator_family_name` _[string]_ - new name of the operator family
- `old_operator_family_name` _[string]_ - old name of the operator family
- `index_method` _[string]_ - name of the index method of operator family
- `new_operator_family_name` _[string]_ - new name of the operator family

@@ -137,5 +137,5 @@ ---

* `operator_family_name` _[string]_ - name of the operator family
* `index_method` _[string]_ - name of the index method of operator family
* `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)
- `operator_family_name` _[string]_ - name of the operator family
- `index_method` _[string]_ - name of the index method of operator family
- `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)

@@ -150,5 +150,5 @@ ---

* `operator_family_name` _[string]_ - name of the operator family
* `index_method` _[string]_ - name of the index method of operator family
* `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)
- `operator_family_name` _[string]_ - name of the operator family
- `index_method` _[string]_ - name of the index method of operator family
- `operator_list` _[array]_ - of [operator objects](#operator-list-definitions)

@@ -161,5 +161,5 @@ ---

* `type` _[string]_ - `function` or `operator`
* `number` _[number]_ - index
* `name` _[string]_ - name of operator or procedure
* `params` _[array]_ - list of argument types of operator or procedure
- `type` _[string]_ - `function` or `operator`
- `number` _[number]_ - index
- `name` _[string]_ - name of operator or procedure
- `params` _[array]_ - list of argument types of operator or procedure

@@ -9,9 +9,9 @@ # Policies Operations

* `tableName` _[string]_ - name of the table to alter
* `policyName` _[string]_ - name of the new policy
* `options` _[object]_ - options:
* `command` _[string]_ - `ALL`, `SELECT`, `INSERT`, `UPDATE`, or `DELETE`
* `role` _[string or array]_ - the role(s) to which the policy is to be applied
* `using` _[string]_ - SQL conditional expression for visibility check
* `check` _[string]_ - SQL conditional expression for insert/update check
- `tableName` _[string]_ - name of the table to alter
- `policyName` _[string]_ - name of the new policy
- `options` _[object]_ - options:
- `command` _[string]_ - `ALL`, `SELECT`, `INSERT`, `UPDATE`, or `DELETE`
- `role` _[string or array]_ - the role(s) to which the policy is to be applied
- `using` _[string]_ - SQL conditional expression for visibility check
- `check` _[string]_ - SQL conditional expression for insert/update check

@@ -28,6 +28,6 @@ **Reverse Operation:** `dropPolicy`

* `tableName` _[string]_ - name of the table where the policy is
* `policyName` _[string]_ - name of the policy to delete
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops policy only if it exists
- `tableName` _[string]_ - name of the table where the policy is
- `policyName` _[string]_ - name of the policy to delete
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops policy only if it exists

@@ -42,8 +42,8 @@ ---

* `tableName` _[string]_ - name of the table where the policy is
* `policyName` _[string]_ - name of the policy to alter
* `options` _[object]_ - options:
* `role` _[string or array]_ - the role(s) to which the policy is to be applied
* `using` _[string]_ - SQL conditional expression for visibility check
* `check` _[string]_ - SQL conditional expression for insert/update check
- `tableName` _[string]_ - name of the table where the policy is
- `policyName` _[string]_ - name of the policy to alter
- `options` _[object]_ - options:
- `role` _[string or array]_ - the role(s) to which the policy is to be applied
- `using` _[string]_ - SQL conditional expression for visibility check
- `check` _[string]_ - SQL conditional expression for insert/update check

@@ -58,4 +58,4 @@ ---

* `tableName` _[string]_ - name of the table where the policy is
* `policyName` _[string]_ - old name of the policy
* `newPolicyName` _[string]_ - new name of the policy
- `tableName` _[string]_ - name of the table where the policy is
- `policyName` _[string]_ - old name of the policy
- `newPolicyName` _[string]_ - new name of the policy

@@ -9,18 +9,18 @@ # Role Operations

* `role_name` _[string]_ - name of the new role
* `role_options` _[object]_ - options:
* `superuser` _[boolean]_ - default false
* `createdb` _[boolean]_ - default false
* `createrole` _[boolean]_ - default false
* `inherit` _[boolean]_ - default true
* `login` _[boolean]_ - default false
* `replication` _[boolean]_ - default false
* `bypassrls` _[boolean]_
* `limit` _[number]_ -
* `password` _[string]_ -
* `encrypted` _[boolean]_ - default true
* `valid` _[string]_ - timestamp
* `inRole` _[string or array of strings]_ - role or array of roles
* `role` _[string or array of strings]_ - role or array of roles
* `admin` _[string or array of strings]_ - role or array of roles
- `role_name` _[string]_ - name of the new role
- `role_options` _[object]_ - options:
- `superuser` _[boolean]_ - default false
- `createdb` _[boolean]_ - default false
- `createrole` _[boolean]_ - default false
- `inherit` _[boolean]_ - default true
- `login` _[boolean]_ - default false
- `replication` _[boolean]_ - default false
- `bypassrls` _[boolean]_
- `limit` _[number]_ -
- `password` _[string]_ -
- `encrypted` _[boolean]_ - default true
- `valid` _[string]_ - timestamp
- `inRole` _[string or array of strings]_ - role or array of roles
- `role` _[string or array of strings]_ - role or array of roles
- `admin` _[string or array of strings]_ - role or array of roles

@@ -37,3 +37,3 @@ **Reverse Operation:** `dropRole`

* `role_name` _[string]_ - name of the new role
- `role_name` _[string]_ - name of the new role

@@ -48,4 +48,4 @@ ---

* `role_name` _[string]_ - name of the new role
* `role_options` _[object]_ - [see](#pgmcreaterole-role_name-role_options-)
- `role_name` _[string]_ - name of the new role
- `role_options` _[object]_ - [see](#pgmcreaterole-role_name-role_options-)

@@ -60,3 +60,3 @@ ---

* `old_role_name` _[string]_ - old name of the role
* `new_role_name` _[string]_ - new name of the role
- `old_role_name` _[string]_ - old name of the role
- `new_role_name` _[string]_ - new name of the role

@@ -9,6 +9,6 @@ # Schema Operations

* `schema_name` _[string]_ - name of the new schema
* `schema_options` _[object]_ - options:
* `ifNotExists` _[boolean]_ - adds `IF NOT EXISTS` clause
* `authorization` _[string]_ - alternative user to own new schema
- `schema_name` _[string]_ - name of the new schema
- `schema_options` _[object]_ - options:
- `ifNotExists` _[boolean]_ - adds `IF NOT EXISTS` clause
- `authorization` _[string]_ - alternative user to own new schema

@@ -25,6 +25,6 @@ **Reverse Operation:** `dropSchema`

* `schema_name` _[string]_ - name of the schema to drop
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops schema only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `schema_name` _[string]_ - name of the schema to drop
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops schema only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -39,3 +39,3 @@ ---

* `old_schema_name` _[string]_ - old name of the schema
* `new_schema_name` _[string]_ - new name of the schema
- `old_schema_name` _[string]_ - old name of the schema
- `new_schema_name` _[string]_ - new name of the schema
# Sequence Operations
### `pgm.createSequence( sequence_name, type, options )`
### `pgm.createSequence( sequence_name, options )`

@@ -9,14 +9,14 @@ > Create a new sequence - [postgres docs](https://www.postgresql.org/docs/current/static/sql-createsequence.html)

* `sequence_name` _[string]_ - name of the new sequence
* `options` _[object]_ - options:
* `temporary` _[boolean]_ - adds `TEMPORARY` clause
* `ifNotExists` _[boolean]_ - adds `IF NOT EXISTS` clause
* `type` _[string]_ - type of the sequence
* `increment` _[number]_ - sets first value of sequence
* `minvalue` _[number or boolean]_ - sets minimum value of sequence or `NO MINVALUE` (on false or null value)
* `maxvalue` _[number or boolean]_ - sets maximum value of sequencee or `NO MAXVALUE` (on false or null value)
* `start` _[number]_ - sets first value of sequence
* `cache` _[number]_ - sets how many sequence numbers should be preallocated
* `cycle` _[boolean]_ - adds `CYCLE` or `NO CYCLE` clause if option is present
* `owner` _[string or boolean]_ - sets owner of sequence or no owner (on false or null value)
- `sequence_name` _[string]_ - name of the new sequence
- `options` _[object]_ - options:
- `temporary` _[boolean]_ - adds `TEMPORARY` clause
- `ifNotExists` _[boolean]_ - adds `IF NOT EXISTS` clause
- `type` _[string]_ - type of the sequence
- `increment` _[number]_ - sets first value of sequence
- `minvalue` _[number or boolean]_ - sets minimum value of sequence or `NO MINVALUE` (on false or null value)
- `maxvalue` _[number or boolean]_ - sets maximum value of sequencee or `NO MAXVALUE` (on false or null value)
- `start` _[number]_ - sets first value of sequence
- `cache` _[number]_ - sets how many sequence numbers should be preallocated
- `cycle` _[boolean]_ - adds `CYCLE` or `NO CYCLE` clause if option is present
- `owner` _[string or boolean]_ - sets owner of sequence or no owner (on false or null value)

@@ -33,6 +33,6 @@ **Reverse Operation:** `dropSequence`

* `sequence_name` _[string]_ - name of the the sequence to drop
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops sequence only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `sequence_name` _[string]_ - name of the the sequence to drop
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops sequence only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -47,13 +47,13 @@ ---

* `sequence_name` _[string]_ - name of the new sequence
* `options` _[object]_ - options:
* `type` _[string]_ - type of the sequence
* `increment` _[number]_ - sets first value of sequence
* `minvalue` _[number or boolean]_ - sets minimum value of sequence or `NO MINVALUE` (on false or null value)
* `maxvalue` _[number or boolean]_ - sets maximum value of sequencee or `NO MAXVALUE` (on false or null value)
* `start` _[number]_ - sets first value of sequence (no effect until restart)
* `restart` _[number or boolean]_ - sets first value of sequence or using `start` value (on true value)
* `cache` _[number]_ - sets how many sequence numbers should be preallocated
* `cycle` _[boolean]_ - adds `CYCLE` or `NO CYCLE` clause if option is present
* `owner` _[string or boolean]_ - sets owner of sequence or no owner (on false or null value)
- `sequence_name` _[string]_ - name of the new sequence
- `options` _[object]_ - options:
- `type` _[string]_ - type of the sequence
- `increment` _[number]_ - sets first value of sequence
- `minvalue` _[number or boolean]_ - sets minimum value of sequence or `NO MINVALUE` (on false or null value)
- `maxvalue` _[number or boolean]_ - sets maximum value of sequencee or `NO MAXVALUE` (on false or null value)
- `start` _[number]_ - sets first value of sequence (no effect until restart)
- `restart` _[number or boolean]_ - sets first value of sequence or using `start` value (on true value)
- `cache` _[number]_ - sets how many sequence numbers should be preallocated
- `cycle` _[boolean]_ - adds `CYCLE` or `NO CYCLE` clause if option is present
- `owner` _[string or boolean]_ - sets owner of sequence or no owner (on false or null value)

@@ -68,3 +68,3 @@ ---

* `old_sequence_name` _[string]_ - old name of the sequence
* `new_sequence_name` _[string]_ - new name of the sequence
- `old_sequence_name` _[string]_ - old name of the sequence
- `new_sequence_name` _[string]_ - new name of the sequence

@@ -9,11 +9,11 @@ # Table Operations

* `tablename` _[string]_ - name for the new table
* `columns` _[object]_ - column names / options -- see [column definitions section](columns.md#column-definitions)
* `options` _[object]_ - table options (optional)
* `temporary` _[bool]_ - default false
* `ifNotExists` _[bool]_ - default false
* `inherits` _[string]_ - table(s) to inherit from
* `constraints` _[object]_ - table constraints see [add constraint](constraints.md#pgmaddconstraint-tablename-constraint_name-expression-)
* `like` _[string]_ - table(s) to inherit from
* `comment` _[string]_ - adds comment on table
- `tablename` _[string]_ - name for the new table
- `columns` _[object]_ - column names / options -- see [column definitions section](columns.md#column-definitions)
- `options` _[object]_ - table options (optional)
- `temporary` _[bool]_ - default false
- `ifNotExists` _[bool]_ - default false
- `inherits` _[string]_ - table(s) to inherit from
- `constraints` _[object]_ - table constraints see [add constraint](constraints.md#pgmaddconstraint-tablename-constraint_name-expression-)
- `like` _[string]_ - table(s) to inherit from
- `comment` _[string]_ - adds comment on table

@@ -30,6 +30,6 @@ **Reverse Operation:** `dropTable`

* `tablename` _[string]_ - name of the table to drop
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops table only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `tablename` _[string]_ - name of the table to drop
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops table only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -44,4 +44,4 @@ ---

* `tablename` _[string]_ - name of the table to rename
* `new_table` _[object]_ - new name of the table
- `tablename` _[string]_ - name of the table to rename
- `new_table` _[object]_ - new name of the table

@@ -58,4 +58,4 @@ **Reverse Operation:** same operation in opposite direction

* `tablename` _[string]_ - name of the table to alter
* `options` _[object]_ - options:
* `levelSecurity` _[string]_ - `DISABLE`, `ENABLE`, `FORCE`, or `NO FORCE`
- `tablename` _[string]_ - name of the table to alter
- `options` _[object]_ - options:
- `levelSecurity` _[string]_ - `DISABLE`, `ENABLE`, `FORCE`, or `NO FORCE`

@@ -9,15 +9,15 @@ # Trigger Operations

* `table_name` _[string]_ - name of the table where the new trigger will live
* `trigger_name` _[string]_ - name of the new trigger
* `trigger_options` _[object]_ - options:
* `when` _[string]_ - `BEFORE`, `AFTER`, or `INSTEAD OF`
* `operation` _[string or array of strings]_ - `INSERT`, `UPDATE[ OF ...]`, `DELETE` or `TRUNCATE`
* `constraint` _[boolean]_ - creates constraint trigger
* `function` _[string]_ - the name of procedure to execute
* `functionArgs` _[array]_ - parameters of the procedure
* `level` _[string]_ - `STATEMENT`, or `ROW`
* `condition` _[string]_ - condition to met to execute trigger
* `deferrable` _[boolean]_ - flag for deferrable constraint trigger
* `deferred` _[boolean]_ - flag for initially deferred deferrable constraint trigger
* `definition` _[string]_ - optional definition of function which will be created with same name as trigger
- `table_name` _[string]_ - name of the table where the new trigger will live
- `trigger_name` _[string]_ - name of the new trigger
- `trigger_options` _[object]_ - options:
- `when` _[string]_ - `BEFORE`, `AFTER`, or `INSTEAD OF`
- `operation` _[string or array of strings]_ - `INSERT`, `UPDATE[ OF ...]`, `DELETE` or `TRUNCATE`
- `constraint` _[boolean]_ - creates constraint trigger
- `function` _[string]_ - the name of procedure to execute
- `functionArgs` _[array]_ - parameters of the procedure
- `level` _[string]_ - `STATEMENT`, or `ROW`
- `condition` _[string]_ - condition to met to execute trigger
- `deferrable` _[boolean]_ - flag for deferrable constraint trigger
- `deferred` _[boolean]_ - flag for initially deferred deferrable constraint trigger
- `definition` _[string]_ - optional definition of function which will be created with same name as trigger

@@ -34,7 +34,7 @@ **Reverse Operation:** `dropTrigger`

* `table_name` _[string]_ - name of the table where the trigger lives
* `trigger_name` _[string]_ - name of the trigger to drop
* `drop_options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops trigger only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `table_name` _[string]_ - name of the table where the trigger lives
- `trigger_name` _[string]_ - name of the trigger to drop
- `drop_options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops trigger only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -49,4 +49,4 @@ ---

* `table_name` _[string]_ - name of the table where the trigger lives
* `old_trigger_name` _[string]_ - old name of the trigger
* `new_trigger_name` _[string]_ - new name of the trigger
- `table_name` _[string]_ - name of the table where the trigger lives
- `old_trigger_name` _[string]_ - old name of the trigger
- `new_trigger_name` _[string]_ - new name of the trigger

@@ -9,4 +9,4 @@ # Type Operations

* `type_name` _[string]_ - name of the new type
* `values` _[array of strings or object]_ if an array the contents are possible values for an enum type, if an object names and types for a composite type
- `type_name` _[string]_ - name of the new type
- `values` _[array of strings or object]_ if an array the contents are possible values for an enum type, if an object names and types for a composite type

@@ -24,3 +24,3 @@ **Aliases:** `addType`

* `type_name` _[string]_ - name of the new type
- `type_name` _[string]_ - name of the new type

@@ -35,4 +35,4 @@ ---

* `type_name` _[string]_ - name of the type to rename
* `new_type_name` _[string]_ - name of the new type
- `type_name` _[string]_ - name of the type to rename
- `new_type_name` _[string]_ - name of the new type

@@ -47,5 +47,5 @@ ---

* `type_name` _[string]_ - name of the type
* `attribute_name` _[string]_ - name of the attribute to add
* `attribute_type` _[string]_ - type of the attribute to add
- `type_name` _[string]_ - name of the type
- `attribute_name` _[string]_ - name of the attribute to add
- `attribute_type` _[string]_ - type of the attribute to add

@@ -60,6 +60,6 @@ ---

* `type_name` _[string]_ - name of the type
* `attribute_name` _[string]_ - name of the attribute to drop
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - default false
- `type_name` _[string]_ - name of the type
- `attribute_name` _[string]_ - name of the attribute to drop
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - default false

@@ -74,5 +74,5 @@ ---

* `type_name` _[string]_ - name of the type
* `attribute_name` _[string]_ - name of the attribute
* `attribute_type` _[string]_ - new type of the attribute
- `type_name` _[string]_ - name of the type
- `attribute_name` _[string]_ - name of the attribute
- `attribute_type` _[string]_ - new type of the attribute

@@ -87,8 +87,8 @@ ---

* `type_name` _[string]_ - name of the type
* `value` _[string]_ - value to add to list
* `options` _[object]_ - options:
* `ifNotExists` _[boolean]_ - default false
* `before` _[string]_ - value before which the new value should be add
* `after` _[string]_ - value after which the new value should be add
- `type_name` _[string]_ - name of the type
- `value` _[string]_ - value to add to list
- `options` _[object]_ - options:
- `ifNotExists` _[boolean]_ - default false
- `before` _[string]_ - value before which the new value should be add
- `after` _[string]_ - value after which the new value should be add

@@ -103,4 +103,4 @@ ---

* `type_name` _[string]_ - name of the type
* `attribute_name` _[string]_ - name of the attribute to rename
* `new_attribute_name` _[string]_ - new name of the attribute
- `type_name` _[string]_ - name of the type
- `attribute_name` _[string]_ - name of the attribute to rename
- `new_attribute_name` _[string]_ - new name of the attribute

@@ -9,10 +9,10 @@ # View Operations

* `viewName` _[string]_ - name of the new view
* `options` _[object]_ - options:
* `temporary` _[boolean]_ - default false
* `replace` _[boolean]_ - default false
* `recursive` _[boolean]_ - default false
* `columns` _[string or array]_ - use if you want to name columns differently then inferred from definition
* `checkOption` _[string]_ - `CASCADED` or `LOCAL`
* `definition` _[string]_ - SQL of SELECT statement
- `viewName` _[string]_ - name of the new view
- `options` _[object]_ - options:
- `temporary` _[boolean]_ - default false
- `replace` _[boolean]_ - default false
- `recursive` _[boolean]_ - default false
- `columns` _[string or array]_ - use if you want to name columns differently then inferred from definition
- `checkOption` _[string]_ - `CASCADED` or `LOCAL`
- `definition` _[string]_ - SQL of SELECT statement

@@ -29,6 +29,6 @@ **Reverse Operation:** `dropView`

* `viewName` _[string]_ - name of the view to delete
* `options` _[object]_ - options:
* `ifExists` _[boolean]_ - drops view only if it exists
* `cascade` _[boolean]_ - drops also dependent objects
- `viewName` _[string]_ - name of the view to delete
- `options` _[object]_ - options:
- `ifExists` _[boolean]_ - drops view only if it exists
- `cascade` _[boolean]_ - drops also dependent objects

@@ -43,5 +43,5 @@ ---

* `viewName` _[string]_ - name of the view to alter
* `options` _[object]_ - options:
* `checkOption` _[string]_ - `CASCADED`, `LOCAL` or `null` to drop
- `viewName` _[string]_ - name of the view to alter
- `options` _[object]_ - options:
- `checkOption` _[string]_ - `CASCADED`, `LOCAL` or `null` to drop

@@ -56,6 +56,6 @@ ---

* `viewName` _[string]_ - name of the view to alter
* `columnName` _[string]_ - name of the column to alter
* `options` _[object]_ - options:
* `default` _[string]_ - default value of column
- `viewName` _[string]_ - name of the view to alter
- `columnName` _[string]_ - name of the column to alter
- `options` _[object]_ - options:
- `default` _[string]_ - default value of column

@@ -70,3 +70,3 @@ ---

* `viewName` _[string]_ - old name of the view
* `newViewName` _[string]_ - new name of the view
- `viewName` _[string]_ - old name of the view
- `newViewName` _[string]_ - new name of the view
{
"name": "node-pg-migrate",
"version": "3.3.0",
"version": "3.4.0",
"description": "Postgresql database migration management tool for node.js",

@@ -34,3 +34,3 @@ "author": "Theo Ephraim",

"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},

@@ -73,3 +73,3 @@ "bugs": {

"prettier": "^1.11.1",
"sinon": "^4.0.0",
"sinon": "^5.0.0",
"sinon-chai": "^3.0.0"

@@ -100,3 +100,4 @@ },

"lint": "eslint -c eslintrc.js . bin/*",
"lintfix": "npm run lint -- --fix",
"lintfix":
"npm run lint -- --fix && prettier --write *.json *.md docs/*.md",
"prepare": "npm run compile"

@@ -103,0 +104,0 @@ },

@@ -87,23 +87,23 @@ # node-pg-migrate

* [CLI](docs/cli.md)
* [Programmatic API](docs/api.md)
* [Defining Migrations](docs/migrations.md)
* [Tables](docs/tables.md)
* [Columns](docs/columns.md)
* [Constraints](docs/constraints.md)
* [Indexes](docs/indexes.md)
* [Functions](docs/functions.md)
* [Triggers](docs/triggers.md)
* [Schemas](docs/schemas.md)
* [Sequences](docs/sequences.md)
* [Views](docs/views.md)
* [Materialized Views](docs/mViews.md)
* [Types](docs/types.md)
* [Domains](docs/domains.md)
* [Operators](docs/operators.md)
* [Roles](docs/roles.md)
* [Policies](docs/policies.md)
* [Extensions](docs/extensions.md)
* [Miscellaneous](docs/misc.md)
* [Transpiling migrations](docs/transpiling.md)
- [CLI](docs/cli.md)
- [Programmatic API](docs/api.md)
- [Defining Migrations](docs/migrations.md)
- [Tables](docs/tables.md)
- [Columns](docs/columns.md)
- [Constraints](docs/constraints.md)
- [Indexes](docs/indexes.md)
- [Functions](docs/functions.md)
- [Triggers](docs/triggers.md)
- [Schemas](docs/schemas.md)
- [Sequences](docs/sequences.md)
- [Views](docs/views.md)
- [Materialized Views](docs/mViews.md)
- [Types](docs/types.md)
- [Domains](docs/domains.md)
- [Operators](docs/operators.md)
- [Roles](docs/roles.md)
- [Policies](docs/policies.md)
- [Extensions](docs/extensions.md)
- [Miscellaneous](docs/misc.md)
- [Transpiling migrations](docs/transpiling.md)

@@ -110,0 +110,0 @@ ## Explanation & Goals

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc