<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250903153815 extends AbstractMigration
{
public function getDescription(): string
{
return 'Cria tabela std_top10 para snapshots de páginas mais vistas';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE `std_top10` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`page_id` INT UNSIGNED NOT NULL COMMENT 'Page unique identifier',
`views_count` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Total de visualizações no período do snapshot',
`is_active` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Flag that indicates if the snapshot is active',
`created_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Data/hora de criação do registro',
`updated_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Data/hora da última atualização do registro',
PRIMARY KEY (`id`),
KEY `idx_std_top10_page_id` (`page_id`),
KEY `idx_std_top10_created_date` (`created_date`),
CONSTRAINT `fk_std_top10_std_pages`
FOREIGN KEY (`page_id`) REFERENCES `std_pages` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE `utf8mb4_unicode_ci`;
SQL);
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE IF EXISTS `std_top10`');
}
}