forked from salsita/node-pg-migrate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new Promise constructor antipattern around promises * unhandled rejection caused by calling `end()` on mocked client
- Loading branch information
Showing
18 changed files
with
164 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (1);')) | ||
.then(() => reject(new Error('Missing check clause'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;')) | ||
) | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (20);')) | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_unique;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (20);')) | ||
.then(() => reject(new Error('Missing not unique clause'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_unique;')) | ||
) | ||
.then(resolve) | ||
); | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (1);')) | ||
.then( | ||
() => Promise.reject(new Error('Missing check clause')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;') | ||
) | ||
) | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (20);')) | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_unique;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nr) VALUES (20);')) | ||
.then( | ||
() => Promise.reject(new Error('Missing not unique clause')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_unique;') | ||
) | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_smallint;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (2147483647);')) | ||
.then(() => reject(new Error('Type not updated'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_smallint;')) | ||
) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_smallint;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (2147483647);')) | ||
.then( | ||
() => Promise.reject(new Error('Type not updated')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_smallint;') | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (30);')) | ||
.then(() => reject(new Error('Missing check clause'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;')) | ||
) | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (21);')) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (30);')) | ||
.then( | ||
() => Promise.reject(new Error('Missing check clause')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;') | ||
) | ||
.then(() => pgm.db.query('INSERT INTO t1(nmbr) VALUES (21);')); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_smallint;') | ||
.then(() => pgm.db.query("select (ROW(2147483647, 'x')::obj).id;")) | ||
.then(() => reject(new Error('Type not updated'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_smallint;')) | ||
) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_smallint;') | ||
.then(() => pgm.db.query("select (ROW(2147483647, 'x')::obj).id;")) | ||
.then( | ||
() => Promise.reject(new Error('Type not updated')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_smallint;') | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_attr;') | ||
.then(() => pgm.db.query("select (ROW(1, 'x')::obj).str;")) | ||
.then(() => reject(new Error('Attribute was not removed'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_attr;')) | ||
) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_attr;') | ||
.then(() => pgm.db.query("select (ROW(1, 'x')::obj).str;")) | ||
.then( | ||
() => Promise.reject(new Error('Attribute was not removed')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_attr;') | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_drop;') | ||
.then(() => | ||
pgm.db.query('CREATE TEMPORARY TABLE t_list_3 (l list_for_drop);') | ||
) | ||
.then(() => reject(new Error('Type was not removed'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_drop;')) | ||
) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_drop;') | ||
.then(() => | ||
pgm.db.query('CREATE TEMPORARY TABLE t_list_3 (l list_for_drop);') | ||
) | ||
.then( | ||
() => Promise.reject(new Error('Type was not removed')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_drop;') | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
pgm.db | ||
.select('SELECT add(1,2) as r') | ||
.then(([{ r }]) => | ||
r === 3 ? resolve() : reject(new Error('Function does not work')) | ||
) | ||
); | ||
pgm.db.select('SELECT add(1,2) as r').then(([{ r }]) => { | ||
if (r !== 3) throw new Error('Function does not work'); | ||
}); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
pgm.db | ||
.select('INSERT INTO tt (a) VALUES (1) RETURNING a') | ||
.then(([{ a }]) => | ||
a === 2 ? resolve() : reject(new Error('Trigger does not work')) | ||
) | ||
); | ||
pgm.db | ||
.select('INSERT INTO tt (a) VALUES (1) RETURNING a;') | ||
.then(([{ a }]) => { | ||
if (a !== 2) throw new Error('Trigger does not work'); | ||
}); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.resolve() | ||
.then(() => | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO td (d) VALUES (11);')) | ||
.then(() => reject(new Error('Check on domain was not set'))) | ||
.catch(() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;')) | ||
) | ||
.then(resolve) | ||
); | ||
pgm.db | ||
.query('SAVEPOINT sp_check;') | ||
.then(() => pgm.db.query('INSERT INTO td (d) VALUES (11);')) | ||
.then( | ||
() => Promise.reject(new Error('Check on domain was not set')), | ||
() => pgm.db.query('ROLLBACK TO SAVEPOINT sp_check;') | ||
); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
pgm.db | ||
.select('INSERT INTO ts DEFAULT VALUES RETURNING id;') | ||
.then(([{ id }]) => | ||
id === 10 ? resolve() : reject(new Error('Bad sequence value')) | ||
) | ||
); | ||
pgm.db | ||
.select('INSERT INTO ts DEFAULT VALUES RETURNING id;') | ||
.then(([{ id }]) => { | ||
if (id !== 10) throw new Error('Bad sequence value'); | ||
}); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
pgm.db | ||
.select('INSERT INTO ts DEFAULT VALUES RETURNING id;') | ||
.then(([{ id }]) => | ||
id === 20 ? resolve() : reject(new Error('Bad sequence value')) | ||
) | ||
); | ||
pgm.db | ||
.select('INSERT INTO ts DEFAULT VALUES RETURNING id;') | ||
.then(([{ id }]) => { | ||
if (id !== 20) throw new Error('Bad sequence value'); | ||
}); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
pgm.db | ||
.select('SELECT ROW(1,2)::complex + ROW(3,4)::complex as sum;') | ||
.then(([{ sum }]) => | ||
sum === '(4,6)' ? resolve() : reject(new Error('Bad sequence value')) | ||
) | ||
); | ||
pgm.db | ||
.select('SELECT ROW(1,2)::complex + ROW(3,4)::complex as sum;') | ||
.then(([{ sum }]) => { | ||
if (sum !== '(4,6)') throw new Error('Bad sequence value'); | ||
}); | ||
|
||
exports.down = () => null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
exports.up = pgm => | ||
new Promise((resolve, reject) => | ||
Promise.all([ | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('admin');"), | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('alice');"), | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('bob');") | ||
]) | ||
.then(() => pgm.db.query('set role admin;')) | ||
.then(() => pgm.db.select('SELECT * FROM tp;')) | ||
.then( | ||
({ length }) => | ||
length === 3 || reject(new Error('Policy is not enforced')) | ||
) | ||
.then(() => pgm.db.query('set role alice;')) | ||
.then(() => pgm.db.select('SELECT * FROM tp;')) | ||
.then( | ||
({ length }) => | ||
length === 1 || reject(new Error('Policy is not enforced')) | ||
) | ||
.then(() => pgm.db.query('reset role;')) | ||
.then(resolve) | ||
); | ||
Promise.all([ | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('admin');"), | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('alice');"), | ||
pgm.db.query("INSERT INTO tp(user_name) VALUES ('bob');") | ||
]) | ||
.then(() => pgm.db.query('set role admin;')) | ||
.then(() => pgm.db.select('SELECT * FROM tp;')) | ||
.then(({ length }) => { | ||
if (length !== 3) throw new Error('Policy is not enforced'); | ||
}) | ||
.then(() => pgm.db.query('set role alice;')) | ||
.then(() => pgm.db.select('SELECT * FROM tp;')) | ||
.then(({ length }) => { | ||
if (length !== 1) throw new Error('Policy is not enforced'); | ||
}) | ||
.then(() => pgm.db.query('reset role;')); | ||
|
||
exports.down = () => null; |
Oops, something went wrong.