<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220316153430 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create table setting.';
}
public function up(Schema $schema): void
{
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS setting (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(256),
type VARCHAR(100),
data JSON NOT NULL ,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
SQL;
$this->addSql($sql);
$sql = <<<SQL
CREATE OR REPLACE TRIGGER setting_update BEFORE UPDATE ON setting FOR EACH ROW
SET NEW.updated_at = NOW();
SQL;
$this->addSql($sql);
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE setting');
}
}