diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-08-13 14:06:28 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-08-13 14:06:28 +0100 |
commit | b5710b291fd44ea7cacb9487de08bd4deba07f59 (patch) | |
tree | 4add90ef2cd7f0dce6658e20c213dcbfa3384e43 /bin/update-schema | |
parent | 60b3ea26baca8010486fc00c9e60034295e495fd (diff) | |
parent | d9e4afa5ee5e28566871d1ecfc363d547b85a7ed (diff) |
Merge branch 'speed-up-things'
Diffstat (limited to 'bin/update-schema')
-rwxr-xr-x | bin/update-schema | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bin/update-schema b/bin/update-schema index ce193f29c..57d1d8ad3 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,8 @@ 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 '0034' if ! function_exists('ms_current_timestamp'); + 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 +256,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); +} |