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

Type of datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not properly represented by generate command #236

Closed
moseslecce opened this issue Oct 31, 2024 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@moseslecce
Copy link

moseslecce commented Oct 31, 2024

Describe the bug
When running the migrate:generate command the resulting migration code does not include the ON UPDATE value

To Reproduce
Steps to reproduce the behavior:

  1. Create table date_test:
CREATE TABLE `date_test` (
  `id` int NOT NULL AUTO_INCREMENT,
  `updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `a_timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1. Run php artisan migrate:generate

  2. Open resulting migration file to find the following code:

    public function up(): void
    {
        Schema::create('date_test', function (Blueprint $table) {
            $table->integer('id', true);
            $table->dateTime('updated')->nullable()->useCurrent();
            $table->timestamp('a_timestamp')->useCurrentOnUpdate()->nullable()->useCurrent();
        });
    }

Expected behavior
I would expect the updated field to include the details about the ON UPDATE CURRENT_TIMESTAMP. One way to achieve this would be for the 'updated' field to use the following code:

$table->dateTime('updated')->useCurrentOnUpdate()->nullable()->useCurrent();

Details (please complete the following information):

  • DB: MySQL
  • DB Version: 8.0.39
  • Laravel Version: 11.9
  • PHP Version: 8.3.6
  • Migrations Generator Version: 7.0.5

Additional context
If we look at the code inside the isOnUpdateCurrentTimestamp function from src/Repositories/MySQLRepository.php, it only checks AND Type = 'timestamp', so it will not get the correct results regarding "onUpdateCurrentTimestamp" for datetime fields.

@kitloong kitloong self-assigned this Nov 2, 2024
@kitloong kitloong added bug Something isn't working good first issue Good for newcomers labels Nov 2, 2024
@kitloong
Copy link
Owner

kitloong commented Nov 3, 2024

Thank you @moseslecce . This has been fixed and release in v7.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants