migrations/Version20211226104458.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 Version20211226104458 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql("CREATE SCHEMA reminders;");
  18.         $this->addSql("
  19.         CREATE TABLE reminders.handlers (
  20.             id SERIAL,
  21.             code VARCHAR(64) NOT NULL,
  22.             locale VARCHAR(16) NOT NULL,
  23.             controller VARCHAR(255) NOT NULL,
  24.             created_at timestamp(0) without time zone DEFAULT NOW()::timestamp without time zone,
  25.             updated_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  26.             deleted_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  27.             created_by integer,
  28.             updated_by integer,
  29.             deleted_by integer,
  30.             enabled smallint DEFAULT 1 NOT NULL,
  31.             deleted smallint DEFAULT 0 NOT NULL,
  32.             PRIMARY KEY(id)
  33.         )
  34.        ");
  35.         $this->addSql("
  36.         CREATE TRIGGER tgr_reminders_handlers__main_table_history
  37.             BEFORE INSERT OR UPDATE
  38.             ON reminders.handlers
  39.             FOR EACH ROW EXECUTE PROCEDURE main_table_history();
  40.         ");
  41.         $this->addSql("
  42.         CREATE TABLE reminders.logs (
  43.             id SERIAL,
  44.             handler_id integer,
  45.             object_id integer,
  46.             created_at timestamp(0) without time zone DEFAULT NOW()::timestamp without time zone,
  47.             updated_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  48.             deleted_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  49.             created_by integer,
  50.             updated_by integer,
  51.             deleted_by integer,
  52.             enabled smallint DEFAULT 1 NOT NULL,
  53.             deleted smallint DEFAULT 0 NOT NULL,
  54.             PRIMARY KEY(id)
  55.         )
  56.        ");
  57.         $this->addSql("
  58.         ALTER TABLE ONLY reminders.logs
  59.             ADD CONSTRAINT fk_reminders_logs__handler_id
  60.             FOREIGN KEY (handler_id)
  61.             REFERENCES reminders.handlers(id)
  62.             ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
  63.         ");
  64.         $this->addSql("
  65.         CREATE TRIGGER tgr_reminders_logs__main_table_history
  66.             BEFORE INSERT OR UPDATE
  67.             ON reminders.logs
  68.             FOR EACH ROW EXECUTE PROCEDURE main_table_history();
  69.         ");
  70.     }
  71.     public function down(Schema $schema): void
  72.     {
  73.         $this->addSql("DROP TABLE reminders.handlers");
  74.         $this->addSql("DROP TABLE reminders.logs");
  75.     }
  76. }