migrations/Version20220316153430.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220316153430 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Create table setting.';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $sql = <<<SQL
  18.             CREATE TABLE IF NOT EXISTS setting (
  19.                 id INT PRIMARY KEY AUTO_INCREMENT,
  20.                 name VARCHAR(256),
  21.                 type VARCHAR(100),
  22.                 data JSON NOT NULL ,
  23.                 updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  24.                 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
  25.            );
  26.         SQL;
  27.         $this->addSql($sql);
  28.         $sql = <<<SQL
  29.              CREATE OR REPLACE TRIGGER setting_update BEFORE UPDATE ON setting FOR EACH ROW
  30.                  SET NEW.updated_at = NOW();
  31.          SQL;
  32.         $this->addSql($sql);
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         $this->addSql('DROP TABLE setting');
  37.     }
  38. }