<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261015120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Track when users and images were created and last updated';
}
public function up(Schema $schema): void
{
foreach (['user', 'image'] as $table) {
$this->addSql("ALTER TABLE `$table` ADD created DATETIME DEFAULT NULL, ADD updated DATETIME DEFAULT NULL");
// Existing rows have no history, so the migration time is the best value we have.
$this->addSql("UPDATE `$table` SET created = NOW(), updated = NOW()");
$this->addSql("ALTER TABLE `$table` CHANGE created created DATETIME NOT NULL, CHANGE updated updated DATETIME NOT NULL");
}
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE `user` DROP created, DROP updated');
$this->addSql('ALTER TABLE image DROP created, DROP updated');
}
}