Skip to content

Commit

Permalink
Merge 03d9f41 into b57788e
Browse files Browse the repository at this point in the history
  • Loading branch information
jonny64 committed Oct 26, 2022
2 parents b57788e + 03d9f41 commit 41ad883
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Eludia/SQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,12 @@ sub assert {

wish (table_keys => [map {{name => $_, parts => $table -> {keys} -> {$_}}} (keys %{$table -> {keys}})], {table => $table -> {name}, table_def => $table}) if exists $table -> {keys};

if (exists $table -> {triggers}) {

wish (table_triggers => [map {{name => $_, body => $table -> {triggers} -> {$_}}} (keys %{$table -> {triggers}})], {table => $table -> {name}});

}

if (exists $table -> {data} && ref $table -> {data} eq ARRAY && @{$table -> {data}} > 0) {

wish (table_data => $table -> {data}, {
Expand Down
73 changes: 73 additions & 0 deletions Eludia/SQL/Dialect/MySQL/Wish/table_triggers.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#############################################################################

sub wish_to_clarify_demands_for_table_triggers {

my ($i, $options) = @_;

my ($phase, @events) = split /_/, $i -> {name};

$i -> {phase} = uc $phase;

$i -> {events} = [sort map {uc} @events];

my $tail = lc (join '_', (
$i -> {phase},
@{$i -> {events}},
$options -> {table}
));

length $tail < 61 or $tail = Digest::MD5::md5_hex ($tail);

$i -> {global_name} = 'on_' . $tail;

}

#############################################################################

sub wish_to_actually_create_table_triggers {

my ($items, $options) = @_;

foreach my $i (@$items) {

my $events = join ' OR ', @{$i -> {events}};

foreach my $sql (

qq {
DROP TRIGGER IF EXISTS
$i->{global_name}
;
},

qq {
CREATE TRIGGER
$i->{global_name}
$i->{phase} $events ON
$options->{table}
FOR EACH ROW
BEGIN
$i->{body}
END;
},

) {

$sql =~ s{\s+}{ }gsm;
$sql =~ s{^ }{};
$sql =~ s{ $}{};

local $conf -> {core_auto_postgresql} = 0;
sql_do ($sql);
}


}

}

1;
13 changes: 13 additions & 0 deletions Eludia/SQL/Wish/table_triggers.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#############################################################################

sub wish_to_adjust_options_for_table_triggers {}

#############################################################################

sub wish_to_explore_existing_table_triggers {{}}

#############################################################################

sub wish_to_schedule_cleanup_for_table_triggers {}

1;

0 comments on commit 41ad883

Please sign in to comment.