migrations/Version20261015120000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20261015120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Track when users and images were created and last updated';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         foreach (['user', 'image'] as $table) {
  15.             $this->addSql("ALTER TABLE `$table` ADD created DATETIME DEFAULT NULL, ADD updated DATETIME DEFAULT NULL");
  16.             // Existing rows have no history, so the migration time is the best value we have.
  17.             $this->addSql("UPDATE `$table` SET created = NOW(), updated = NOW()");
  18.             $this->addSql("ALTER TABLE `$table` CHANGE created created DATETIME NOT NULL, CHANGE updated updated DATETIME NOT NULL");
  19.         }
  20.     }
  21.     public function down(Schema $schema): void
  22.     {
  23.         $this->addSql('ALTER TABLE `user` DROP created, DROP updated');
  24.         $this->addSql('ALTER TABLE image DROP created, DROP updated');
  25.     }
  26. }