Last active
April 6, 2023 22:09
-
-
Save popovserhii/03bf8331de76ed4daa21706afe6222b3 to your computer and use it in GitHub Desktop.
Doctrine add "ON UPDATE CURRENT_TIMESTAMP" and default value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use DateTime; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* @var DateTime | |
* | |
* @Gedmo\Timestampable(on="create") | |
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"}) | |
*/ | |
private $created; | |
/** | |
* @var DateTime | |
* | |
* @Gedmo\Timestampable(on="update") | |
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"}, columnDefinition="DATETIME ON UPDATE CURRENT_TIMESTAMP") | |
*/ | |
private $updated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function up(Schema $schema): void | |
{ | |
$this->addSql('ALTER TABLE agg_project_finance | |
CHANGE `created` `created` DATETIME NOT NULL DEFAULT current_timestamp, | |
CHANGE `updated` `updated` DATETIME NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp | |
'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment