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

FRW-2182 extend TimestampableBehavior with is_timestamp parameter to allow configuration of datetime type for created_at and updated_at #1971

Open
maritechpro opened this issue Jun 26, 2023 · 3 comments · May be fixed by #1978

Comments

@maritechpro
Copy link

maritechpro commented Jun 26, 2023

FRW-2182 extend TimestampableBehavior with is_timestamp parameter to allow configuration of datetime type for created_at and updated_at

Behavior should be extendable on 2.0.0-beta2 (2.0.1-beta2) and 2.0.0-beta3 (2.0.1-beta3) versions.
Thank you.

@maritechpro
Copy link
Author

  1. Adjust field TimestampableBehavior::parameters
    /**
     * @var array<string, mixed>
     */
    protected $parameters = [
        'create_column' => 'created_at',
        'update_column' => 'updated_at',
        'disable_created_at' => 'false',
        'disable_updated_at' => 'false',
        'is_timestamp' => 'true',
    ];
  1. Add method TimestampableBehavior::isTimestamp() :

    /**
     * @return bool
     */
    protected function isTimestamp(): bool
    {
        return $this->booleanValue($this->getParameter('is_timestamp'));
    }
  1. Adjust method TimestampableBehavior::modifyTable() :

    /**
     * Add the create_column and update_columns to the current table
     *
     * @return void
     */
    public function modifyTable(): void
    {
        $table = $this->getTable();

        if ($this->withCreatedAt() && !$table->hasColumn($this->getParameter('create_column'))) {
            $table->addColumn([
                'name' => $this->getParameter('create_column'),
                'type' => $this->isTimestamp() ? 'TIMESTAMP' : 'DATETIME',
            ]);
        }
        if ($this->withUpdatedAt() && !$table->hasColumn($this->getParameter('update_column'))) {
            $table->addColumn([
                'name' => $this->getParameter('update_column'),
                'type' => $this->isTimestamp() ? 'TIMESTAMP' : 'DATETIME',
            ]);
        }
    }

@maritechpro maritechpro changed the title FRW-2812 extend TimestampableBehavior with is_timestamp parameter to allow configuration of datetime type for created_at and updated_at FRW-2182 extend TimestampableBehavior with is_timestamp parameter to allow configuration of datetime type for created_at and updated_at Jun 26, 2023
@wollanup
Copy link
Contributor

Hey, I'm opening a PR with your code @maritechpro and will try to add some tests.

@SilverSnake83
Copy link

I would greatly appreciate this kind of changes. The propel diff are now nearly impossible to use due to thousands of detected diff that must be manually deleted from the result of the diff everytime.
For instance :

ALTER TABLE `table`

  CHANGE `created_at` `created_at` TIMESTAMP NULL,

  CHANGE `updated_at` `updated_at` TIMESTAMP NULL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants