migrations/Version20200311135917.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 Version20200311135917 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  19.         $this->addSql('CREATE SEQUENCE devices_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  20.         $this->addSql('CREATE SEQUENCE data_samples_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  21.         $this->addSql('CREATE SEQUENCE project_information_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  22.         $this->addSql('CREATE SEQUENCE measurements_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  23.         $this->addSql('CREATE SEQUENCE probes_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  24.         $this->addSql('CREATE SEQUENCE recipes_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  25.         $this->addSql('CREATE SEQUENCE customers_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  26.         $this->addSql('CREATE SEQUENCE channels_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  27.         $this->addSql('CREATE SEQUENCE cached_responses_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  28.         $this->addSql('CREATE SEQUENCE user_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
  29.         $this->addSql('CREATE TABLE devices (id INT NOT NULL, customer_id INT DEFAULT NULL, serial_number VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  30.         $this->addSql('CREATE INDEX IDX_11074E9A9395C3F3 ON devices (customer_id)');
  31.         $this->addSql('COMMENT ON COLUMN devices.serial_number IS \'Serial number.\'');
  32.         $this->addSql('COMMENT ON COLUMN devices.created_at IS \'Date of the entity creation. Should be fixed.\'');
  33.         $this->addSql('COMMENT ON COLUMN devices.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  34.         $this->addSql('CREATE TABLE data_samples (id INT NOT NULL, device_id INT NOT NULL, recipe_id INT NOT NULL, started_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, measured_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, measuring_interval DOUBLE PRECISION NOT NULL, battery_level TEXT DEFAULT NULL, status INT NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  35.         $this->addSql('CREATE INDEX IDX_7D99018694A4C7D4 ON data_samples (device_id)');
  36.         $this->addSql('CREATE INDEX IDX_7D99018659D8A214 ON data_samples (recipe_id)');
  37.         $this->addSql('COMMENT ON COLUMN data_samples.started_at IS \'Started at.\'');
  38.         $this->addSql('COMMENT ON COLUMN data_samples.measured_at IS \'Measured at.\'');
  39.         $this->addSql('COMMENT ON COLUMN data_samples.measuring_interval IS \'Measuring interval.\'');
  40.         $this->addSql('COMMENT ON COLUMN data_samples.battery_level IS \'Battery level.\'');
  41.         $this->addSql('COMMENT ON COLUMN data_samples.status IS \'Allowed values: START, RUN, STOP.\'');
  42.         $this->addSql('COMMENT ON COLUMN data_samples.created_at IS \'Date of the entity creation. Should be fixed.\'');
  43.         $this->addSql('COMMENT ON COLUMN data_samples.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  44.         $this->addSql('CREATE TABLE project_information (id INT NOT NULL, measurement_id INT NOT NULL, heading TEXT DEFAULT NULL, content TEXT DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  45.         $this->addSql('CREATE INDEX IDX_E1B6EF78924EA134 ON project_information (measurement_id)');
  46.         $this->addSql('COMMENT ON COLUMN project_information.heading IS \'Information key.\'');
  47.         $this->addSql('COMMENT ON COLUMN project_information.content IS \'Information value.\'');
  48.         $this->addSql('COMMENT ON COLUMN project_information.created_at IS \'Date of the entity creation. Should be fixed.\'');
  49.         $this->addSql('COMMENT ON COLUMN project_information.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  50.         $this->addSql('CREATE TABLE measurements (id INT NOT NULL, device_id INT NOT NULL, customer_id INT DEFAULT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  51.         $this->addSql('CREATE INDEX IDX_71920F2194A4C7D4 ON measurements (device_id)');
  52.         $this->addSql('CREATE INDEX IDX_71920F219395C3F3 ON measurements (customer_id)');
  53.         $this->addSql('COMMENT ON COLUMN measurements.created_at IS \'Date of the entity creation. Should be fixed.\'');
  54.         $this->addSql('COMMENT ON COLUMN measurements.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  55.         $this->addSql('CREATE TABLE probes (id INT NOT NULL, data_sample_id INT NOT NULL, channel_id INT NOT NULL, temperature INT NOT NULL, time TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
  56.         $this->addSql('CREATE INDEX IDX_C06258B294B0AA16 ON probes (data_sample_id)');
  57.         $this->addSql('CREATE INDEX IDX_C06258B272F5A1AA ON probes (channel_id)');
  58.         $this->addSql('COMMENT ON COLUMN probes.temperature IS \'Temperature.\'');
  59.         $this->addSql('CREATE TABLE recipes (id INT NOT NULL, name TEXT NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  60.         $this->addSql('COMMENT ON COLUMN recipes.name IS \'Recipe name.\'');
  61.         $this->addSql('COMMENT ON COLUMN recipes.created_at IS \'Date of the entity creation. Should be fixed.\'');
  62.         $this->addSql('COMMENT ON COLUMN recipes.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  63.         $this->addSql('CREATE TABLE customers (id INT NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  64.         $this->addSql('COMMENT ON COLUMN customers.created_at IS \'Date of the entity creation. Should be fixed.\'');
  65.         $this->addSql('COMMENT ON COLUMN customers.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  66.         $this->addSql('CREATE TABLE channels (id INT NOT NULL, recipe_id INT DEFAULT NULL, measurement_id INT NOT NULL, channel_number INT NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  67.         $this->addSql('CREATE INDEX IDX_F314E2B659D8A214 ON channels (recipe_id)');
  68.         $this->addSql('CREATE INDEX IDX_F314E2B6924EA134 ON channels (measurement_id)');
  69.         $this->addSql('COMMENT ON COLUMN channels.channel_number IS \'Channel number.\'');
  70.         $this->addSql('COMMENT ON COLUMN channels.created_at IS \'Date of the entity creation. Should be fixed.\'');
  71.         $this->addSql('COMMENT ON COLUMN channels.updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  72.         $this->addSql('CREATE TABLE cached_responses (id INT NOT NULL, request_id TEXT NOT NULL, response_code INT NOT NULL, response TEXT NOT NULL, route VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
  73.         $this->addSql('CREATE TABLE "user" (id INT NOT NULL, customer_id INT DEFAULT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
  74.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON "user" (email)');
  75.         $this->addSql('CREATE INDEX IDX_8D93D6499395C3F3 ON "user" (customer_id)');
  76.         $this->addSql('COMMENT ON COLUMN "user".created_at IS \'Date of the entity creation. Should be fixed.\'');
  77.         $this->addSql('COMMENT ON COLUMN "user".updated_at IS \'Date of the last change in entity. Shouldn’t be set to other dates.\'');
  78.         $this->addSql('ALTER TABLE devices ADD CONSTRAINT FK_11074E9A9395C3F3 FOREIGN KEY (customer_id) REFERENCES customers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  79.         $this->addSql('ALTER TABLE data_samples ADD CONSTRAINT FK_7D99018694A4C7D4 FOREIGN KEY (device_id) REFERENCES devices (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  80.         $this->addSql('ALTER TABLE data_samples ADD CONSTRAINT FK_7D99018659D8A214 FOREIGN KEY (recipe_id) REFERENCES recipes (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  81.         $this->addSql('ALTER TABLE project_information ADD CONSTRAINT FK_E1B6EF78924EA134 FOREIGN KEY (measurement_id) REFERENCES measurements (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  82.         $this->addSql('ALTER TABLE measurements ADD CONSTRAINT FK_71920F2194A4C7D4 FOREIGN KEY (device_id) REFERENCES devices (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  83.         $this->addSql('ALTER TABLE measurements ADD CONSTRAINT FK_71920F219395C3F3 FOREIGN KEY (customer_id) REFERENCES customers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  84.         $this->addSql('ALTER TABLE probes ADD CONSTRAINT FK_C06258B294B0AA16 FOREIGN KEY (data_sample_id) REFERENCES data_samples (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  85.         $this->addSql('ALTER TABLE probes ADD CONSTRAINT FK_C06258B272F5A1AA FOREIGN KEY (channel_id) REFERENCES channels (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  86.         $this->addSql('ALTER TABLE channels ADD CONSTRAINT FK_F314E2B659D8A214 FOREIGN KEY (recipe_id) REFERENCES recipes (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  87.         $this->addSql('ALTER TABLE channels ADD CONSTRAINT FK_F314E2B6924EA134 FOREIGN KEY (measurement_id) REFERENCES measurements (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  88.         $this->addSql('ALTER TABLE "user" ADD CONSTRAINT FK_8D93D6499395C3F3 FOREIGN KEY (customer_id) REFERENCES customers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  89.     }
  90.     public function down(Schema $schema) : void
  91.     {
  92.         // this down() migration is auto-generated, please modify it to your needs
  93.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql''Migration can only be executed safely on \'postgresql\'.');
  94.         $this->addSql('CREATE SCHEMA public');
  95.         $this->addSql('ALTER TABLE data_samples DROP CONSTRAINT FK_7D99018694A4C7D4');
  96.         $this->addSql('ALTER TABLE measurements DROP CONSTRAINT FK_71920F2194A4C7D4');
  97.         $this->addSql('ALTER TABLE probes DROP CONSTRAINT FK_C06258B294B0AA16');
  98.         $this->addSql('ALTER TABLE project_information DROP CONSTRAINT FK_E1B6EF78924EA134');
  99.         $this->addSql('ALTER TABLE channels DROP CONSTRAINT FK_F314E2B6924EA134');
  100.         $this->addSql('ALTER TABLE data_samples DROP CONSTRAINT FK_7D99018659D8A214');
  101.         $this->addSql('ALTER TABLE channels DROP CONSTRAINT FK_F314E2B659D8A214');
  102.         $this->addSql('ALTER TABLE devices DROP CONSTRAINT FK_11074E9A9395C3F3');
  103.         $this->addSql('ALTER TABLE measurements DROP CONSTRAINT FK_71920F219395C3F3');
  104.         $this->addSql('ALTER TABLE "user" DROP CONSTRAINT FK_8D93D6499395C3F3');
  105.         $this->addSql('ALTER TABLE probes DROP CONSTRAINT FK_C06258B272F5A1AA');
  106.         $this->addSql('DROP SEQUENCE devices_id_seq CASCADE');
  107.         $this->addSql('DROP SEQUENCE data_samples_id_seq CASCADE');
  108.         $this->addSql('DROP SEQUENCE project_information_id_seq CASCADE');
  109.         $this->addSql('DROP SEQUENCE measurements_id_seq CASCADE');
  110.         $this->addSql('DROP SEQUENCE probes_id_seq CASCADE');
  111.         $this->addSql('DROP SEQUENCE recipes_id_seq CASCADE');
  112.         $this->addSql('DROP SEQUENCE customers_id_seq CASCADE');
  113.         $this->addSql('DROP SEQUENCE channels_id_seq CASCADE');
  114.         $this->addSql('DROP SEQUENCE cached_responses_id_seq CASCADE');
  115.         $this->addSql('DROP SEQUENCE user_id_seq CASCADE');
  116.         $this->addSql('DROP TABLE devices');
  117.         $this->addSql('DROP TABLE data_samples');
  118.         $this->addSql('DROP TABLE project_information');
  119.         $this->addSql('DROP TABLE measurements');
  120.         $this->addSql('DROP TABLE probes');
  121.         $this->addSql('DROP TABLE recipes');
  122.         $this->addSql('DROP TABLE customers');
  123.         $this->addSql('DROP TABLE channels');
  124.         $this->addSql('DROP TABLE cached_responses');
  125.         $this->addSql('DROP TABLE "user"');
  126.     }
  127. }