Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: timestamp columns parse default value set as Fragment #201

Open
1 task done
AnrDaemon opened this issue May 16, 2024 · 1 comment
Open
1 task done

[Bug]: timestamp columns parse default value set as Fragment #201

AnrDaemon opened this issue May 16, 2024 · 1 comment
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@AnrDaemon
Copy link

AnrDaemon commented May 16, 2024

No duplicates 🥲.

  • I have searched for a similar issue in our bug tracker and didn't find any solutions.

Describe the bug

Trying to execute migration with default value set as Fragment

$table
        ->addColumn('ttl', 'timestamp', [
            'nullable' => true,
            'default' => new Fragment('ADDTIME(`Date`, \'2:00:00\')'),
        ]);

causes exception DateTimeImmutable::__construct(): Failed to parse time string (addtime(`Date`,'2:00:00')) at position 0 (a): The timezone could not be found in the database.

Full backtrace:

Exception: DateTimeImmutable::__construct(): Failed to parse time string (addtime(`Date`,'2:00:00')) at position 0 (a): The timezone could not be found in the database in ~/vendor/cycle/database/src/Schema/AbstractColumn.php:754
Stack trace:
#0 ~/vendor/cycle/database/src/Schema/AbstractColumn.php(754): DateTimeImmutable->__construct()
#1 ~/vendor/cycle/database/src/Driver/MySQL/Schema/MySQLColumn.php(372): Cycle\Database\Schema\AbstractColumn->formatDatetime()
#2 ~/vendor/cycle/database/src/Schema/AbstractColumn.php(370): Cycle\Database\Driver\MySQL\Schema\MySQLColumn->formatDatetime()
#3 ~/vendor/cycle/database/src/Schema/AbstractColumn.php(666): Cycle\Database\Schema\AbstractColumn->getDefaultValue()
#4 ~/vendor/cycle/database/src/Driver/MySQL/Schema/MySQLColumn.php(299): Cycle\Database\Schema\AbstractColumn->compare()
#5 ~/vendor/cycle/database/src/Schema/Comparator.php(108): Cycle\Database\Driver\MySQL\Schema\MySQLColumn->compare()
#6 ~/vendor/cycle/database/src/Schema/AbstractTable.php(705): Cycle\Database\Schema\Comparator->alteredColumns()
#7 ~/vendor/cycle/database/src/Schema/AbstractTable.php(619): Cycle\Database\Schema\AbstractTable->normalizeSchema()
#8 ~/vendor/cycle/migrations/src/Operation/Table/Update.php(28): Cycle\Database\Schema\AbstractTable->save()
#9 ~/vendor/cycle/migrations/src/Capsule.php(69): Cycle\Migrations\Operation\Table\Update->execute()
#10 ~/vendor/cycle/migrations/src/TableBlueprint.php(243): Cycle\Migrations\Capsule->execute()
#11 ~/vendor/cycle/migrations/src/TableBlueprint.php(197): Cycle\Migrations\TableBlueprint->execute()
#12 ~/schema/inv/20231013.155347_0_inv.ip_ipmi_role.php(32): Cycle\Migrations\TableBlueprint->update()
#13 ~/dev/seeding-executor.php(73): ~\Migrations\inv\migrationclass->up()
#14 ~/vendor/cycle/database/src/Database.php(188): ~\Migrations\{closure}()
#15 ~/dev/seeding-executor.php(74): Cycle\Database\Database->transaction()
#16 {main}

Is this a regression?

Not that I know.

To Reproduce

class MigrationClass extends Migration {

    /**
     * Create tables, add columns or insert data here
     */
    public function up() {
        $this->table('table_a')
                ->addColumn('ttl', 'timestamp', [
                    'nullable' => true,
                    'default' => new Fragment('ADDTIME(`Date`, \'2:00:00\')'),
                ])
                ->update();
    }

    /**
     * Drop created, columns and etc here
     */
    public function down() {
        $this->table('table_a')
            ->dropColumn('ttl')
            ->update();
    }
}

Expected behaviour

A column should be added with default value set to +2 hours from time of row creation.

Media prove

No response

Database

MySQL

Your environment

  • OS: CentOs Stream
  • PHP 8.0.30
  • cycle/migrations 3.1.0
  • cycle/database 2.7.0

Additional context

No response

@AnrDaemon AnrDaemon added the status:to be verified Needs to be reproduced and validated. label May 16, 2024
@AnrDaemon AnrDaemon changed the title [Bug]: [Bug]: timestamp columns parse default value set as Fragment May 16, 2024
@roxblnfk roxblnfk added this to Cycle May 16, 2024
@roxblnfk roxblnfk moved this to Todo in Cycle May 16, 2024
@AnrDaemon
Copy link
Author

After some additional investigation, it turned out the issue arise when Cycle tries to understand the database structure.
I.e.:

Step#1: Creating database with such column: it's fine.
Step#2: Reading the table from database (f.e. to further modify it) in the next migration: fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
Status: Todo
Development

No branches or pull requests

1 participant