<?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 Version20200528171156 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql("
ALTER TABLE `std_forms`
ADD COLUMN `read_by` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `updated_by`,
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`,
ADD COLUMN `read_date` DATETIME NULL AFTER `updated_date`,
ADD CONSTRAINT `FK_std_forms_std_users` FOREIGN KEY (`read_by`) REFERENCES `std_users` (`id`);
INSERT INTO `std_domains` (`updated_by`, `language_code`, `created_by`, `machine_name`, `description`, `created_date`, `updated_date`)
VALUES ('1', 'pt', '1', 'form_type', 'Tipos de formulários', '2020-05-28 18:59:33', '2020-05-28 18:59:34');
SET @id_domain = LAST_INSERT_ID();
INSERT INTO `std_domains_values` (`updated_by`, `language_code`, `created_by`, `domain_id`, `machine_name`, `description`, `created_date`, `updated_date`)
VALUES ('1', 'pt', '1', @id_domain, 'default', 'Geral', '2020-05-28 19:00:49', '2020-05-28 19:00:49');
SET @id_ct_forms = (SELECT id FROM std_content_types WHERE machine_name='forms');
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`)
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\"}');
");
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql("
SET @id_ct_forms = (SELECT id FROM std_content_types WHERE machine_name='forms');
DELETE FROM std_content_types_components WHERE machine_name='form_type' and content_type_id=@id_ct_forms;
SET @id_domain = (select id from std_domains where machine_name='form_type' and language_code='pt');
DELETE FROM std_domains_values WHERE domain_id=@id_domain;
DELETE FROM std_domains WHERE id=@id_domain;
ALTER TABLE `std_forms`
DROP COLUMN `read_by`,
DROP COLUMN `form_type`,
DROP COLUMN `read_date`,
DROP FOREIGN KEY `FK_std_forms_std_users`;
");
}
}