Skip to content

Commit

Permalink
fix timestamp DEFAULT_GENERATED
Browse files Browse the repository at this point in the history
  • Loading branch information
jygaulier committed Feb 22, 2024
1 parent eef0b05 commit 0b76baf
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/Alchemy/Phrasea/Core/Database/DatabaseMaintenanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ public function upgradeTable(\SimpleXMLElement $table, OutputInterface $output)
$expr = trim((string)$field->type);

$_extra = trim((string)$field->extra);
$type = trim(strtolower((string)$field->type));
$_default = (string)$field->default;

if ($_extra) {
$expr .= ' ' . $_extra;
}

$collation = trim((string)$field->collation) != '' ? trim((string)$field->collation) : 'utf8_unicode_ci';

$type = trim(strtolower((string)$field->type));
if (in_array($type, ['text', 'longtext', 'mediumtext', 'tinytext'])
|| substr($type, 0, 7) == 'varchar'
|| in_array(substr($type, 0, 4), ['char', 'enum'])
Expand All @@ -322,16 +324,16 @@ public function upgradeTable(\SimpleXMLElement $table, OutputInterface $output)
$expr .= ' NOT NULL';
}

$_default = (string)$field->default;
if ($_default && $_default != 'CURRENT_TIMESTAMP') {
$expr .= ' DEFAULT \'' . $_default . '\'';
} elseif ($_default == 'CURRENT_TIMESTAMP') {
$expr .= ' DEFAULT ' . $_default . '';
}

$expr8 = preg_replace('/^(\\w*int)(\\(\\d+\\))?(.*)?$/', '$1$3', $expr);
$correct_table['fields'][trim((string)$field->name)] = [
'expr' => $expr,
'expr8' => preg_replace('/^(\\w*int)(\\(\\d+\\))?(.*)?$/', '$1$3', $expr)
'expr8' => $expr8
];
}
if ($table->indexes) {
Expand Down Expand Up @@ -429,6 +431,12 @@ public function upgradeTable(\SimpleXMLElement $table, OutputInterface $output)
}

if (isset($correct_table['fields'][$f_name])) {

$matches = [];
if(preg_match("/^timestamp DEFAULT_GENERATED/", $expr_found, $matches) === 1) {
$correct_table['fields'][$f_name] = preg_replace("/^timestamp/", "timestamp DEFAULT_GENERATED", $correct_table['fields'][$f_name]);
}

if (isset($correct_table['collation'][$f_name]) && $correct_table['collation'][$f_name] != $current_collation) {
$old_type = mb_strtolower(trim($row2['Type']));
$new_type = false;
Expand Down

0 comments on commit 0b76baf

Please sign in to comment.