aboutsummaryrefslogtreecommitdiffstats
path: root/bin/update-schema
diff options
context:
space:
mode:
Diffstat (limited to 'bin/update-schema')
-rwxr-xr-x[-rw-r--r--]bin/update-schema16
1 files changed, 13 insertions, 3 deletions
diff --git a/bin/update-schema b/bin/update-schema
index 198fa6b8d..be5bc50e7 100644..100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -19,13 +19,14 @@ use mySociety::DBHandle qw(dbh);
use mySociety::MaPit;
mySociety::Config::set_file("$FindBin::Bin/../conf/general");
-mySociety::DBHandle::configure(
+my %args = (
Name => mySociety::Config::get('FMS_DB_NAME'),
User => mySociety::Config::get('FMS_DB_USER'),
Password => mySociety::Config::get('FMS_DB_PASS'),
- Host => mySociety::Config::get('FMS_DB_HOST', undef),
- Port => mySociety::Config::get('FMS_DB_PORT', undef)
);
+$args{Host} = mySociety::Config::get('FMS_DB_HOST', undef) if mySociety::Config::get('FMS_DB_HOST');
+$args{Port} = mySociety::Config::get('FMS_DB_PORT', undef) if mySociety::Config::get('FMS_DB_PORT');
+mySociety::DBHandle::configure( %args );
my $commit = 0;
$commit = 1 if @ARGV && $ARGV[0] eq '--commit';
@@ -85,6 +86,8 @@ print "Nothing to do\n" if $nothing;
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
return '0031' if column_exists('body', 'external_url');
+ return '0030' if ! constraint_exists('admin_log_action_check');
+ return '0029' if column_exists('body', 'deleted');
return '0028' if table_exists('body');
return '0027' if column_exists('problem', 'subcategory');
return '0026' if column_exists('open311conf', 'send_extended_statuses');
@@ -133,3 +136,10 @@ sub column_like {
my ( $table, $where, $column, $contents ) = @_;
return dbh()->selectrow_array("select count(*) from $table WHERE $where AND $column LIKE ?", {}, "%$contents%");
}
+
+# Returns true if a check constraint on a table exists
+sub constraint_exists {
+ my ( $constraint ) = @_;
+ return dbh()->selectrow_array('select count(*) from pg_constraint where conname = ?', {}, $constraint);
+}
+