aboutsummaryrefslogtreecommitdiffstats
path: root/bin/update-schema
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2015-08-13 12:23:46 +0100
committerMatthew Somerville <matthew@mysociety.org>2015-08-13 13:38:13 +0100
commit864fcb6a81b17ec6324598973ff29dd734a7baf8 (patch)
tree853d489ddb1c7102fad57c230e28cc69a45d5d2f /bin/update-schema
parent6329d2b848c405e4e646a4111941e82fcb0f33cb (diff)
Add schema migration check for latest migration.
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);
+}