From d11e1fc579d4832493b99b1baf35e1507729742c Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Thu, 3 Feb 2022 13:01:11 +0100 Subject: [PATCH] fix: drop constraint if different (#1700) --- lib/Ravada.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Ravada.pm b/lib/Ravada.pm index ee00ca8e5..2bab0d332 100644 --- a/lib/Ravada.pm +++ b/lib/Ravada.pm @@ -218,7 +218,7 @@ sub _do_create_constraints($self) { my ($name) = $constraint =~ /CONSTRAINT (\w+)\s/; warn "INFO: creating constraint $name \n" - if !$FIRST_TIME_RUN && $0 !~ /\.t$/; + if $name && !$FIRST_TIME_RUN && $0 !~ /\.t$/; print "+" if $FIRST_TIME_RUN && !$CAN_FORK; $self->_clean_db_leftovers(); @@ -2049,6 +2049,12 @@ sub _create_constraints($self, $table, @constraints) { my $name = "constraint_${table}_$field"; next if $known->{$name} && $known->{$name} eq $sql; + if ($known->{$name}) { + push @{$self->{_constraints}} + ,"alter table $table DROP constraint $name"; + } + + $sql = "alter table $table add CONSTRAINT $name $sql"; # $CONNECTOR->dbh->do($sql); push @{$self->{_constraints}},($sql);