Skip to content

Commit

Permalink
Merge pull request #131 from yvanzo/search-653-drop-previous-sql
Browse files Browse the repository at this point in the history
SEARCH-653: Drop SQL functions and triggers previously created
  • Loading branch information
yvanzo authored May 12, 2022
2 parents 922a341 + 7c6449f commit 47c50f4
Show file tree
Hide file tree
Showing 3 changed files with 598 additions and 573 deletions.
22 changes: 19 additions & 3 deletions GenerateDropSql.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ sub process_functions
my $name = $1;
push @functions, $name;
}
# Functions created by the previous versions of SIR
push @functions, qw(
search_link_attribute_type_insert
search_link_attribute_type_update
search_link_attribute_type_delete
);
@functions = sort(@functions);

my @aggregates;
Expand All @@ -39,11 +45,11 @@ sub process_functions
print OUT "-- Automatically generated, do not edit.\n";
print OUT "\\unset ON_ERROR_STOP\n\n";
foreach my $func (@functions) {
print OUT "DROP FUNCTION $func;\n";
print OUT "DROP FUNCTION IF EXISTS $func;\n";
}
foreach my $agg (@aggregates) {
my ($name, $type) = @$agg;
print OUT "DROP AGGREGATE $name ($type);\n";
print OUT "DROP AGGREGATE IF EXISTS $name ($type);\n";
}
close OUT;
}
Expand All @@ -67,12 +73,22 @@ sub process_triggers
while ($create_triggers_sql =~ m/CREATE (?:CONSTRAINT )?TRIGGER\s+"?([a-z0-9_]+)"?\s+.*?\s+ON\s+"?([a-z0-9_\.]+)"?.*?;/gsi) {
push @triggers, [$1, $2];
}
# Triggers created by the previous versions of SIR
push @triggers, (
['search_release_packaging_insert', 'musicbrainz.release_packaging'],
['search_release_packaging_update', 'musicbrainz.release_packaging'],
['search_release_packaging_delete', 'musicbrainz.release_packaging'],
['search_link_attribute_type_insert', 'musicbrainz.link_attribute_type'],
['search_link_attribute_type_update', 'musicbrainz.link_attribute_type'],
['search_link_attribute_type_delete', 'musicbrainz.link_attribute_type']
);
@triggers = sort(@triggers);

open OUT, ">$dir/$outfile";
print OUT "-- Automatically generated, do not edit.\n";
print OUT "\\unset ON_ERROR_STOP\n\n";
foreach my $trigger (@triggers) {
print OUT "DROP TRIGGER $trigger->[0] ON $trigger->[1];\n";
print OUT "DROP TRIGGER IF EXISTS $trigger->[0] ON $trigger->[1];\n";
}
close OUT;
}
Expand Down
Loading

0 comments on commit 47c50f4

Please sign in to comment.