<?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 Version20210401191017 extends AbstractMigration
{
public function getDescription() : string
{
return 'Initial custom migration';
}
public function up(Schema $schema) : void
{
$this->addSql('CREATE SEQUENCE mt_event_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE mt_event_report_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE digitallink_event_entry_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE digitallink_report_summary_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE geo_location (id SERIAL NOT NULL, ip_start inet NOT NULL, ip_end inet NOT NULL, continent VARCHAR(2) NOT NULL, country VARCHAR(2) NOT NULL, state VARCHAR(72) DEFAULT NULL, district VARCHAR(255) DEFAULT NULL, city VARCHAR(128) DEFAULT NULL, zip_code VARCHAR(24) DEFAULT NULL, latitude VARCHAR(24) NOT NULL, longitude VARCHAR(24) NOT NULL, geo_name_id VARCHAR(12) NOT NULL, timezone_offset VARCHAR(6) DEFAULT NULL, timezone VARCHAR(36) DEFAULT NULL, weather_code VARCHAR(12) DEFAULT NULL, isp_name VARCHAR(255) DEFAULT NULL, as_number VARCHAR(32) DEFAULT NULL, connection_type VARCHAR(12) DEFAULT NULL, organization_name VARCHAR(255) DEFAULT NULL, ip_range numrange NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE mt_event (id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, is_active BOOLEAN DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, uuid UUID NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_36BFD9A3D17F50A6 ON mt_event (uuid)');
$this->addSql('COMMENT ON COLUMN mt_event.uuid IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE mt_event_report (id INT NOT NULL, event_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, handler VARCHAR(32) DEFAULT NULL, needed_criteria VARCHAR(10) DEFAULT NULL, report_service VARCHAR(50) DEFAULT NULL, summary_frequency VARCHAR(15) DEFAULT NULL, is_active BOOLEAN DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, is_live BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_39B92CAB71F7E88B ON mt_event_report (event_id)');
$this->addSql('CREATE TABLE tmp_geo_location (id SERIAL NOT NULL, ip_start inet NOT NULL, ip_end inet NOT NULL, continent VARCHAR(2) NOT NULL, country VARCHAR(2) NOT NULL, state VARCHAR(72) DEFAULT NULL, district VARCHAR(255) DEFAULT NULL, city VARCHAR(128) DEFAULT NULL, zip_code VARCHAR(24) DEFAULT NULL, latitude VARCHAR(24) NOT NULL, longitude VARCHAR(24) NOT NULL, geo_name_id VARCHAR(12) NOT NULL, timezone_offset VARCHAR(6) DEFAULT NULL, timezone VARCHAR(36) DEFAULT NULL, weather_code VARCHAR(12) DEFAULT NULL, isp_name VARCHAR(255) DEFAULT NULL, as_number VARCHAR(32) DEFAULT NULL, connection_type VARCHAR(12) DEFAULT NULL, organization_name VARCHAR(255) DEFAULT NULL, ip_range numrange NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE digitallink_event_entry (id INT NOT NULL, event_id INT NOT NULL, criteria1 INT DEFAULT NULL, criteria2 INT DEFAULT NULL, criteria3 INT DEFAULT NULL, ip VARCHAR(32) DEFAULT NULL, continent_code VARCHAR(5) DEFAULT NULL, country_code VARCHAR(5) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, model VARCHAR(100) DEFAULT NULL, brand_name VARCHAR(100) DEFAULT NULL, os VARCHAR(100) DEFAULT NULL, browser VARCHAR(100) DEFAULT NULL, latitude NUMERIC(9, 6) DEFAULT NULL, longitude NUMERIC(9, 6) DEFAULT NULL, extra JSON DEFAULT NULL, isp VARCHAR(144) DEFAULT NULL, referer VARCHAR(255) DEFAULT NULL, client_type VARCHAR(32) DEFAULT NULL, is_mobile BOOLEAN DEFAULT NULL, recorded_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX uee_criteria1_idx ON digitallink_event_entry (criteria1)');
$this->addSql('CREATE INDEX uee_criteria2_idx ON digitallink_event_entry (criteria2)');
$this->addSql('CREATE INDEX uee_criteria3_idx ON digitallink_event_entry (criteria3)');
$this->addSql('CREATE TABLE digitallink_report_summary (id INT NOT NULL, event_report_id INT DEFAULT NULL, criteria1 INT DEFAULT NULL, criteria2 INT DEFAULT NULL, criteria3 INT DEFAULT NULL, stats_summary JSON DEFAULT NULL, event_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, day_stamp INT DEFAULT NULL, PRIMARY KEY(id, day_stamp)) PARTITION BY RANGE (day_stamp)');
$this->addSql('CREATE INDEX IDX_5446ECA3CD479AFD ON digitallink_report_summary (event_report_id)');
$this->addSql('CREATE INDEX urs_criteria1_idx ON digitallink_report_summary (criteria1)');
$this->addSql('CREATE INDEX urs_criteria2_idx ON digitallink_report_summary (criteria2)');
$this->addSql('CREATE INDEX urs_criteria3_idx ON digitallink_report_summary (criteria3)');
$this->addSql('CREATE INDEX urs_day_stamp_idx ON digitallink_report_summary (day_stamp)');
$this->addSql('ALTER TABLE mt_event_report ADD CONSTRAINT FK_39B92CAB71F7E88B FOREIGN KEY (event_id) REFERENCES mt_event (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE digitallink_report_summary ADD CONSTRAINT FK_5446ECA3CD479AFD FOREIGN KEY (event_report_id) REFERENCES mt_event_report (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addInitialRecords();
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE mt_event_report DROP CONSTRAINT FK_39B92CAB71F7E88B');
$this->addSql('ALTER TABLE digitallink_report_summary DROP CONSTRAINT FK_5446ECA3CD479AFD');
$this->addSql('DROP SEQUENCE mt_event_id_seq CASCADE');
$this->addSql('DROP SEQUENCE mt_event_report_id_seq CASCADE');
$this->addSql('DROP SEQUENCE digitallink_event_entry_id_seq CASCADE');
$this->addSql('DROP SEQUENCE digitallink_report_summary_id_seq CASCADE');
$this->addSql('DROP TABLE mt_event');
$this->addSql('DROP TABLE mt_event_report');
$this->addSql('DROP TABLE digitallink_event_entry');
$this->addSql('DROP TABLE digitallink_report_summary');
}
private function addInitialRecords() {
// Events initial data
$this->addSql("INSERT INTO mt_event(id,uuid,name,description,is_active,created_at) VALUES (nextval('mt_event_id_seq'), '588090d4-8c02-11eb-8dcd-0242ac130003', 'qr_code_scans', 'QR Code Scans', '1', CURRENT_TIMESTAMP)");
// summary Report
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_hour_and_min', 'DigitalLinkTotalByHourAndMinute', '3', 'report_total_by_hour_and_min', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_browser', 'DigitalLinkTotalByBrowser', '3', 'report_total_by_browser', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_os', 'DigitalLinkTotalByOs', '3', 'report_total_by_os', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_country_and_city', 'DigitalLinkTotalByCountryAndCity', '3', 'report_total_by_country_and_city', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_daily', 'DailyTotal', '3', 'report_total_daily', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_isp', 'DigitalLinkTotalByIsp', '3', 'report_total_by_isp', 'daily', '1', '1', CURRENT_TIMESTAMP)");
$this->addSql("INSERT INTO mt_event_report(id,event_id,name,handler,needed_criteria,report_service,summary_frequency,is_active,is_live,created_at) VALUES (nextval('mt_event_report_id_seq'), currval('mt_event_id_seq'), 'report_total_by_brand_and_device', 'DigitalLinkTotalByBrandAndDevice', '3', 'report_total_by_brand_and_device', 'daily', '1', '1', CURRENT_TIMESTAMP)");
}
}