Skip to content

Commit c0ec0e2

Browse files
committed
Improve trigger 'scope' attribute support (RT#119997)
- JSON, YAML and XML producers - XML and SQLite parsers TODO: Unify with the DB2 parser/producer's 'granularity' extra attribute
1 parent 913fea5 commit c0ec0e2

File tree

13 files changed

+24
-9
lines changed

13 files changed

+24
-9
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changes for SQL::Translator
88
* Add support for USING and WHERE on indexes in PostgreSQL producer
99
and parser (RT#63814, GH#52)
1010
* Improve add_trigger consistency between producers (GH#48)
11+
* Add trigger 'scope' attribute support to JSON, YAML and XML producers,
12+
and XML and SQLite parsers (RT#119997)
1113
* Declare dependencies in deterministic order (RT#102859)
1214
* Multiple speedups of naive internal debugging mechanism (GH#54)
1315
* Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle )

lib/SQL/Translator/Parser/SQLite.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ sub parse {
730730
database_events => $def->{'db_events'},
731731
action => $def->{'action'},
732732
on_table => $def->{'on_table'},
733+
scope => 'row', # SQLite only supports row triggers
733734
);
734735
}
735736

lib/SQL/Translator/Parser/XML/SQLFairy.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ sub parse {
216216
foreach (@nodes) {
217217
my %data = get_tagfields($xp, $_, "sqlf:", qw/
218218
name perform_action_when database_event database_events fields
219-
on_table action order extra
219+
on_table action order extra scope
220220
/);
221221

222222
# back compat

lib/SQL/Translator/Producer/JSON.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ sub view_trigger {
149149
'fields' => scalar $trigger->fields,
150150
'on_table' => scalar $trigger->on_table,
151151
'action' => scalar $trigger->action,
152+
'scope' => scalar $trigger->scope,
152153
keys %{$trigger->extra} ? ('extra' => { $trigger->extra } ) : (),
153154
};
154155
}

lib/SQL/Translator/Producer/XML/SQLFairy.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ sub produce {
271271
xml_obj_children( $xml, $schema,
272272
tag => 'trigger',
273273
methods => [qw/name database_events action on_table perform_action_when
274-
fields order extra/],
274+
fields order extra scope/],
275275
);
276276

277277
#

lib/SQL/Translator/Producer/YAML.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ sub view_trigger {
148148
'fields' => scalar $trigger->fields,
149149
'on_table' => scalar $trigger->on_table,
150150
'action' => scalar $trigger->action,
151+
'scope' => scalar $trigger->scope,
151152
keys %{$trigger->extra} ? ('extra' => { $trigger->extra } ) : (),
152153
};
153154
}

lib/Test/SQL/Translator.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ sub trigger_ok {
284284
is( $obj->on_table, $test->{on_table},
285285
"$t_name on_table is '$test->{on_table}'" );
286286

287+
is( $obj->scope, $test->{scope}, "$t_name scope is '$test->{scope}'" )
288+
if exists $test->{scope};
289+
287290
is( $obj->action, $test->{action}, "$t_name action is '$test->{action}'" );
288291

289292
is_deeply( { $obj->extra }, $test->{extra}, "$t_name extra" );

t/16xml-parser.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0);
2727
#=============================================================================
2828

2929
BEGIN {
30-
maybe_plan(238, 'SQL::Translator::Parser::XML::SQLFairy');
30+
maybe_plan(undef, 'SQL::Translator::Parser::XML::SQLFairy');
3131
}
3232

3333
my $testschema = "$Bin/data/xml/schema.xml";
@@ -235,6 +235,7 @@ schema_ok( $scma, {
235235
database_events => 'insert',
236236
on_table => 'Basic',
237237
action => 'update modified=timestamp();',
238+
scope => 'row',
238239
extra => {
239240
foo => "bar",
240241
hello => "world",
@@ -247,6 +248,7 @@ schema_ok( $scma, {
247248
database_events => 'insert,update',
248249
on_table => 'Basic',
249250
action => 'update modified2=timestamp();',
251+
scope => 'row',
250252
extra => {
251253
hello => "aliens",
252254
},
@@ -269,3 +271,5 @@ schema_ok( $scma, {
269271
],
270272

271273
}); # end schema
274+
275+
done_testing;

t/17sqlfxml-producer.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ $ans = <<EOXML;
193193
</tables>
194194
<views></views>
195195
<triggers>
196-
<trigger name="foo_trigger" database_events="insert" on_table="Basic" perform_action_when="after" order="1">
196+
<trigger name="foo_trigger" database_events="insert" on_table="Basic" perform_action_when="after" order="1" scope="row">
197197
<action>update modified=timestamp();</action>
198198
<extra hello="world" />
199199
</trigger>
@@ -222,6 +222,7 @@ EOXML
222222
database_events => [$database_event],
223223
table => $table,
224224
action => $action,
225+
scope => 'row',
225226
extra => { hello => "world" },
226227
) or die $s->error;
227228

t/23json.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ my $json = to_json(from_json(<<JSON), { canonical => 1, pretty => 1 });
260260
"name" : "pet_trig",
261261
"on_table" : "pet",
262262
"order" : "1",
263-
"perform_action_when" : "after"
263+
"perform_action_when" : "after",
264+
"scope": "row"
264265
}
265266
},
266267
"views" : {

0 commit comments

Comments
 (0)