migrations/Version20200528171156.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 Version20200528171156 extends AbstractMigration
  10. {
  11.     public function getDescription() : string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema) : void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql("
  19.         
  20.         ALTER TABLE `std_forms`
  21.         ADD COLUMN `read_by` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `updated_by`,
  22.         ADD COLUMN `form_type` VARCHAR(255) NOT NULL COMMENT 'machine_name da std_domain_values, o id_domain é o com o machine_name=form_type' AFTER `form_name`,
  23.         ADD COLUMN `read_date` DATETIME NULL AFTER `updated_date`,
  24.         ADD CONSTRAINT `FK_std_forms_std_users` FOREIGN KEY (`read_by`) REFERENCES `std_users` (`id`);
  25.         INSERT INTO `std_domains` (`updated_by`, `language_code`, `created_by`, `machine_name`, `description`, `created_date`, `updated_date`) 
  26.         VALUES ('1', 'pt', '1', 'form_type', 'Tipos de formulários', '2020-05-28 18:59:33', '2020-05-28 18:59:34');
  27.         SET @id_domain = LAST_INSERT_ID();
  28.         INSERT INTO `std_domains_values` (`updated_by`, `language_code`, `created_by`, `domain_id`, `machine_name`, `description`, `created_date`, `updated_date`) 
  29.         VALUES ('1', 'pt', '1', @id_domain, 'default', 'Geral', '2020-05-28 19:00:49', '2020-05-28 19:00:49');
  30.         SET @id_ct_forms = (SELECT id FROM std_content_types WHERE machine_name='forms');
  31.         INSERT INTO `std_content_types_components` (`content_type_id`, `machine_name`, `component_type`, `order_value`, `created_by`, `created_date`, `updated_by`, `updated_date`, `name`,`settings`) 
  32.         VALUES (@id_ct_forms, 'form_type', 'COMBO', '0', '1', '2020-05-28 19:20:01', '1', '2020-05-28 19:20:05', 'Form Type','{\"sql\": \"SELECT dv.machine_name AS codigo, dv.description AS descricao FROM std_domains_values dv INNER JOIN std_domains d ON dv.domain_id=d.id WHERE d.machine_name=''form_type'' AND d.language_code=(SELECT language_code FROM std_languages WHERE is_active=1 AND is_public=1 LIMIT 1) AND dv.language_code=(SELECT language_code FROM std_languages WHERE is_active=1 AND is_public=1 LIMIT 1) AND dv.is_active=1 AND d.is_active=1 ORDER BY dv.description \", \"type\": \"dynamic\"}');    
  33.         ");
  34.     }
  35.     public function down(Schema $schema) : void
  36.     {
  37.         // this down() migration is auto-generated, please modify it to your needs
  38.         $this->addSql("
  39.         SET @id_ct_forms = (SELECT id FROM std_content_types WHERE machine_name='forms');
  40.         DELETE FROM std_content_types_components WHERE machine_name='form_type' and content_type_id=@id_ct_forms;
  41.         SET @id_domain = (select id from std_domains where machine_name='form_type' and language_code='pt');
  42.         DELETE FROM std_domains_values WHERE domain_id=@id_domain;
  43.         DELETE FROM std_domains WHERE id=@id_domain;
  44.         ALTER TABLE `std_forms`
  45.         DROP COLUMN `read_by`,
  46.         DROP COLUMN `form_type`,
  47.         DROP COLUMN `read_date`,
  48.         DROP FOREIGN KEY `FK_std_forms_std_users`;
  49.     
  50.         ");
  51.     }
  52. }