diff options
author | Marius Halden <marius.h@lden.org> | 2015-10-27 13:27:03 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-10-27 13:27:03 +0100 |
commit | 4fb5331abd2fa4c89ebeb89bc92a245fadd0aa19 (patch) | |
tree | 23632b448612e3845a6e8b1aed6490151395de2a /bin/update-schema | |
parent | e609613b5041a15491417eaa9ae129dd1e7531dd (diff) | |
parent | ac39951581a0eefe069c8a707bb89977227d0bce (diff) |
Merge tag 'v1.7' into fiksgatami-dev
Diffstat (limited to 'bin/update-schema')
-rwxr-xr-x | bin/update-schema | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/bin/update-schema b/bin/update-schema index ce193f29c..1af08b002 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,12 @@ 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 '0038' if column_exists('admin_log', 'time_spent'); + return '0037' if table_exists('response_templates'); + return '0036' if constraint_contains('problem_cobrand_check', 'a-z0-9_'); + return '0035' if column_exists('problem', 'bodies_missing'); + 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 +260,15 @@ sub constraint_exists { return dbh()->selectrow_array('select count(*) from pg_constraint where conname = ?', {}, $constraint); } +# Returns true if a check constraint contains a certain string +sub constraint_contains { + my ( $constraint, $check ) = @_; + my ($consrc) = dbh()->selectrow_array('select consrc from pg_constraint where conname = ?', {}, $constraint); + return $consrc =~ /$check/; +} + +# Returns true if a function exists +sub function_exists { + my $fn = shift; + return dbh()->selectrow_array('select count(*) from pg_proc where proname = ?', {}, $fn); +} |