[BUG]: Trying to update 3.1.28 to 3.2.25 beta 3 (or 3.2.4) gives error on default value for created. #1201

Open
opened 2025-01-22 14:18:33 +00:00 by Tom van der Laan · 1 comment

What Happened?

When i try to update to newer JCB version i get this error:

Error: updating database schema. Error: failed to create missing joomla_power table. Invalid default value for 'created'

When i change this file (line):

and add this:

 elseif (strtoupper($type) === 'DATETIME' && $this->currentVersion == 3)
		{
			return " DEFAULT '0000-00-00 00:00:00'";
		}

It updates without issues.

Steps to reproduce the Bug

Try to update a 3.1.28 version on Joomla 3 to 3.2.5 beta 3.

Which Joomla version are you compiling in?

3.10.12

Which PHP version are you compiling in?

8.1

Which Joomla versions are you targeting?

3

Which PHP version are you targeting?

8.1

Which Web server is JCB running on?

Apache

Which Relational Database is JCB running on?

Mariadb 10.4

Which OS is JCB running on?

Centos 7

Which JCB version are you using?

3.1.28

Where in JCB did this issue occur?

Other

On which browsers did you encounter the issue?

Safari

Additional Comments

No response

### What Happened? When i try to update to newer JCB version i get this error: Error: updating database schema. Error: failed to create missing joomla_power table. Invalid default value for 'created' When i change this file (line): https://git.vdm.dev/joomla/Component-Builder/src/commit/a3a1c97dae1ca5cde6674c390dd0bc7406c1e22f/libraries/vendor_jcb/VDM.Joomla/src/Abstraction/Schema.php#L815 and add this: ``` elseif (strtoupper($type) === 'DATETIME' && $this->currentVersion == 3) { return " DEFAULT '0000-00-00 00:00:00'"; } ``` It updates without issues. ### Steps to reproduce the Bug Try to update a 3.1.28 version on Joomla 3 to 3.2.5 beta 3. ### Which Joomla version are you compiling in? 3.10.12 ### Which PHP version are you compiling in? 8.1 ### Which Joomla versions are you targeting? 3 ### Which PHP version are you targeting? 8.1 ### Which Web server is JCB running on? Apache ### Which Relational Database is JCB running on? Mariadb 10.4 ### Which OS is JCB running on? Centos 7 ### Which JCB version are you using? 3.1.28 ### Where in JCB did this issue occur? Other ### On which browsers did you encounter the issue? Safari ### Additional Comments _No response_
Tom van der Laan added the
Bug
label 2025-01-22 14:18:33 +00:00
Owner

@TLWebdesign can you confirm that this works?

// Get the database object and version
$dbType = $this->db->getServerType(); // Returns the database type: 'mysql', 'pgsql', etc.
$dbVersion = $this->db->getVersion();

// Logic to handle DATETIME default values based on database type
if (strtoupper($type) === 'DATETIME') {
    if ($dbType === 'mysql') {
        // MySQL-specific logic
        if (version_compare($dbVersion, '5.6', '>=')) {
            return $pure ? "CURRENT_TIMESTAMP" : " DEFAULT CURRENT_TIMESTAMP";
        } else {
            return $pure ? "'0000-00-00 00:00:00'" : " DEFAULT '0000-00-00 00:00:00'";
        }
    } elseif ($dbType === 'pgsql') {
        // PostgreSQL supports CURRENT_TIMESTAMP universally
        return $pure ? "CURRENT_TIMESTAMP" : " DEFAULT CURRENT_TIMESTAMP";
    } else {
        // Unsupported database type
        throw new \RuntimeException("Unsupported database type: {$dbType}");
    }
}

This will be the more correct solution, as the issue really relates to the database version and not the Joomla version.

@TLWebdesign can you confirm that this works? ```php // Get the database object and version $dbType = $this->db->getServerType(); // Returns the database type: 'mysql', 'pgsql', etc. $dbVersion = $this->db->getVersion(); // Logic to handle DATETIME default values based on database type if (strtoupper($type) === 'DATETIME') { if ($dbType === 'mysql') { // MySQL-specific logic if (version_compare($dbVersion, '5.6', '>=')) { return $pure ? "CURRENT_TIMESTAMP" : " DEFAULT CURRENT_TIMESTAMP"; } else { return $pure ? "'0000-00-00 00:00:00'" : " DEFAULT '0000-00-00 00:00:00'"; } } elseif ($dbType === 'pgsql') { // PostgreSQL supports CURRENT_TIMESTAMP universally return $pure ? "CURRENT_TIMESTAMP" : " DEFAULT CURRENT_TIMESTAMP"; } else { // Unsupported database type throw new \RuntimeException("Unsupported database type: {$dbType}"); } } ``` This will be the more correct solution, as the issue really relates to the database version and not the Joomla version.
Sign in to join this conversation.
No Milestone
No project
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1201
No description provided.