Skip to content

Commit

Permalink
MySQL: probe_db() cannot update int fields with MySQL 8.0.17 or later (
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed Oct 18, 2021
1 parent 9d31cce commit 5a931d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/lib/Sympa/Database.pm
Expand Up @@ -430,6 +430,31 @@ sub error {
return undef;
}

# Old name: Sympa::DatabaseManager::_check_db_field_type().
sub is_sufficient_field_type {
my $self = shift;
my $required = shift;
my $effective = shift;

my ($required_type, $required_size, $effective_type, $effective_size);

if ($required =~ /^(\w+)(\((\d+)\))?$/) {
($required_type, $required_size) = ($1, $3);
}

if ($effective =~ /^(\w+)(\((\d+)\))?$/) {
($effective_type, $effective_size) = ($1, $3);
}

if ( ($effective_type // '') eq ($required_type // '')
and (not defined $required_size or $effective_size >= $required_size))
{
return 1;
}

return 0;
}

sub set_persistent {
my $self = shift;
my $flag = shift;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/Sympa/DatabaseDriver/MySQL.pm
Expand Up @@ -330,6 +330,20 @@ sub get_primary_key {
return \%found_keys;
}

sub is_sufficient_field_type {
my $self = shift;
my $required = shift;
my $actual = shift;

# As of MySQL 8.0.17, the display width attribute is deprecated for
# integer data types (MeriaDB has not).
if ($required =~ /\A((?:tiny|small|medium|big)?int)(?:[(]\d+[)])?\z/
and $actual eq $1) {
return 1;
}
return $self->SUPER::is_sufficient_field_type($required, $actual);
}

sub unset_primary_key {
my $self = shift;
my $param = shift;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Sympa/DatabaseManager.pm
Expand Up @@ -361,9 +361,9 @@ sub _check_fields {
## Change DB types if different and if update_db_types enabled
if ($may_update) {
unless (
_check_db_field_type(
effective_format => $real_struct{$t}{$f},
required_format => $db_struct->{$t}->{$f}
$sdm->is_sufficient_field_type(
$db_struct->{$t}->{$f},
$real_struct{$t}{$f}
)
) {
push @{$report_ref},
Expand Down

0 comments on commit 5a931d5

Please sign in to comment.