aboutsummaryrefslogtreecommitdiffstats
path: root/bin/update-schema
diff options
context:
space:
mode:
Diffstat (limited to 'bin/update-schema')
-rwxr-xr-xbin/update-schema10
1 files changed, 8 insertions, 2 deletions
diff --git a/bin/update-schema b/bin/update-schema
index ce193f29c..15cb6cd59 100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -95,8 +95,8 @@ sub get_statements {
next if /^--/; # Ignore comments
$s .= $_;
# Functions may have semicolons within them
- $in_function = 1 if /create function/i;
- $in_function = 0 if /language 'plpgsql'/i;
+ $in_function = 1 if /create (or replace )?function/i;
+ $in_function = 0 if /language (sql|'plpgsql')/i;
if ($s =~ /;/ && !$in_function) {
push @statements, $s;
$s = '';
@@ -195,6 +195,7 @@ else {
# By querying the database schema, we can see where we're currently at
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
+ return '0033' if ! function_exists('angle_between');
return '0032' if table_exists('moderation_original_data');
return '0031' if column_exists('body', 'external_url');
return '0030' if ! constraint_exists('admin_log_action_check');
@@ -254,3 +255,8 @@ sub constraint_exists {
return dbh()->selectrow_array('select count(*) from pg_constraint where conname = ?', {}, $constraint);
}
+# Returns true if a function exists
+sub function_exists {
+ my $fn = shift;
+ return dbh()->selectrow_array('select count(*) from pg_proc where proname = ?', {}, $fn);
+}