Skip to content

Commit 47c50f4

Browse files
authored
Merge pull request #131 from yvanzo/search-653-drop-previous-sql
SEARCH-653: Drop SQL functions and triggers previously created
2 parents 922a341 + 7c6449f commit 47c50f4

File tree

3 files changed

+598
-573
lines changed

3 files changed

+598
-573
lines changed

GenerateDropSql.pl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ sub process_functions
2727
my $name = $1;
2828
push @functions, $name;
2929
}
30+
# Functions created by the previous versions of SIR
31+
push @functions, qw(
32+
search_link_attribute_type_insert
33+
search_link_attribute_type_update
34+
search_link_attribute_type_delete
35+
);
3036
@functions = sort(@functions);
3137

3238
my @aggregates;
@@ -39,11 +45,11 @@ sub process_functions
3945
print OUT "-- Automatically generated, do not edit.\n";
4046
print OUT "\\unset ON_ERROR_STOP\n\n";
4147
foreach my $func (@functions) {
42-
print OUT "DROP FUNCTION $func;\n";
48+
print OUT "DROP FUNCTION IF EXISTS $func;\n";
4349
}
4450
foreach my $agg (@aggregates) {
4551
my ($name, $type) = @$agg;
46-
print OUT "DROP AGGREGATE $name ($type);\n";
52+
print OUT "DROP AGGREGATE IF EXISTS $name ($type);\n";
4753
}
4854
close OUT;
4955
}
@@ -67,12 +73,22 @@ sub process_triggers
6773
while ($create_triggers_sql =~ m/CREATE (?:CONSTRAINT )?TRIGGER\s+"?([a-z0-9_]+)"?\s+.*?\s+ON\s+"?([a-z0-9_\.]+)"?.*?;/gsi) {
6874
push @triggers, [$1, $2];
6975
}
76+
# Triggers created by the previous versions of SIR
77+
push @triggers, (
78+
['search_release_packaging_insert', 'musicbrainz.release_packaging'],
79+
['search_release_packaging_update', 'musicbrainz.release_packaging'],
80+
['search_release_packaging_delete', 'musicbrainz.release_packaging'],
81+
['search_link_attribute_type_insert', 'musicbrainz.link_attribute_type'],
82+
['search_link_attribute_type_update', 'musicbrainz.link_attribute_type'],
83+
['search_link_attribute_type_delete', 'musicbrainz.link_attribute_type']
84+
);
85+
@triggers = sort(@triggers);
7086

7187
open OUT, ">$dir/$outfile";
7288
print OUT "-- Automatically generated, do not edit.\n";
7389
print OUT "\\unset ON_ERROR_STOP\n\n";
7490
foreach my $trigger (@triggers) {
75-
print OUT "DROP TRIGGER $trigger->[0] ON $trigger->[1];\n";
91+
print OUT "DROP TRIGGER IF EXISTS $trigger->[0] ON $trigger->[1];\n";
7692
}
7793
close OUT;
7894
}

0 commit comments

Comments
 (0)