不要怂,就是干,撸起袖子干!

Commit bde6d501 by Maurice Ronet Dominguez Committed by Sushant

fix(queryGenerator): createTrigger fails with correct event specs (#8282)

1 parent 0ca7299f
......@@ -713,11 +713,11 @@ const QueryGenerator = {
'truncate': 'TRUNCATE'
};
if (!Utils._.has(EVENT_MAP, fireKey)) {
if (!Utils._.has(EVENT_MAP, fireValue)) {
throw new Error('parseTriggerEventSpec: undefined trigger event ' + fireKey);
}
let eventSpec = EVENT_MAP[fireKey];
let eventSpec = EVENT_MAP[fireValue];
if (eventSpec === 'UPDATE') {
if (Utils._.isArray(fireValue) && fireValue.length > 0) {
eventSpec += ' OF ' + fireValue.join(', ');
......
......@@ -422,7 +422,7 @@ if (dialect.match(/^postgres/)) {
}, {
title: 'string in array should escape \' as \'\'',
arguments: ['myTable', {where: { aliases: {$contains: ['Queen\'s']} }}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"aliases\" @> ARRAY['Queen''s'];",
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"aliases\" @> ARRAY['Queen''s'];"
},
// Variants when quoteIdentifiers is false
......@@ -904,6 +904,25 @@ if (dialect.match(/^postgres/)) {
expectation: 'ROLLBACK TO SAVEPOINT \"transaction-uid\";',
context: {options: {quoteIdentifiers: true}}
}
],
createTrigger: [
{
arguments: ['myTable', 'myTrigger', 'after', ['insert'], 'myFunction', [], []],
expectation: 'CREATE TRIGGER myTrigger\n\tAFTER INSERT\n\tON myTable\n\t\n\tEXECUTE PROCEDURE myFunction();'
},
{
arguments: ['myTable', 'myTrigger', 'before', ['insert', 'update'], 'myFunction', [{name: 'bar', type: 'INTEGER'}], []],
expectation: 'CREATE TRIGGER myTrigger\n\tBEFORE INSERT OR UPDATE\n\tON myTable\n\t\n\tEXECUTE PROCEDURE myFunction(bar INTEGER);'
},
{
arguments: ['myTable', 'myTrigger', 'instead_of', ['insert', 'update'], 'myFunction', [], ['FOR EACH ROW']],
expectation: 'CREATE TRIGGER myTrigger\n\tINSTEAD OF INSERT OR UPDATE\n\tON myTable\n\t\n\tFOR EACH ROW\n\tEXECUTE PROCEDURE myFunction();'
},
{
arguments: ['myTable', 'myTrigger', 'after_constraint', ['insert', 'update'], 'myFunction', [{name: 'bar', type: 'INTEGER'}], ['FOR EACH ROW']],
expectation:'CREATE CONSTRAINT TRIGGER myTrigger\n\tAFTER INSERT OR UPDATE\n\tON myTable\n\t\n\tFOR EACH ROW\n\tEXECUTE PROCEDURE myFunction(bar INTEGER);'
}
]
};
......@@ -924,6 +943,7 @@ if (dialect.match(/^postgres/)) {
if (_.isFunction(test.arguments[1])) test.arguments[1] = test.arguments[1](this.sequelize);
if (_.isFunction(test.arguments[2])) test.arguments[2] = test.arguments[2](this.sequelize);
}
QueryGenerator.options = _.assign(context.options, { timezone: '+00:00' });
QueryGenerator._dialect = this.sequelize.dialect;
QueryGenerator.sequelize = this.sequelize;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!