brilo-example/migrations/Version20240804103624.php

73 lines
4.9 KiB
PHP
Raw Permalink Normal View History

<?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 Version20240804103624 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('CREATE SEQUENCE addresses_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE companies_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE addresses (id INT NOT NULL, street TEXT NOT NULL, suite TEXT NOT NULL, city TEXT NOT NULL, zipcode TEXT NOT NULL, lat DOUBLE PRECISION NOT NULL, lng DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE comments (id INT NOT NULL, post_id INT DEFAULT NULL, name TEXT NOT NULL, email VARCHAR(320) NOT NULL, body TEXT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_5F9E962A4B89032C ON comments (post_id)');
$this->addSql('CREATE TABLE companies (id INT NOT NULL, name TEXT NOT NULL, catch_phrase TEXT NOT NULL, bs TEXT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8244AA3A5E237E06 ON companies (name)');
$this->addSql('CREATE TABLE posts (id INT NOT NULL, user_id INT DEFAULT NULL, title TEXT NOT NULL, body TEXT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_885DBAFAA76ED395 ON posts (user_id)');
$this->addSql('CREATE TABLE users (id INT NOT NULL, address_id INT DEFAULT NULL, company_id INT DEFAULT NULL, name TEXT NOT NULL, username TEXT NOT NULL, email TEXT NOT NULL, phone TEXT NOT NULL, website TEXT NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9F5B7AF75 ON users (address_id)');
$this->addSql('CREATE INDEX IDX_1483A5E9979B1AD6 ON users (company_id)');
$this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)');
$this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)');
$this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)');
$this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;');
$this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;');
$this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();');
$this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A4B89032C FOREIGN KEY (post_id) REFERENCES posts (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFAA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E9F5B7AF75 FOREIGN KEY (address_id) REFERENCES addresses (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E9979B1AD6 FOREIGN KEY (company_id) REFERENCES companies (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP SEQUENCE addresses_id_seq CASCADE');
$this->addSql('DROP SEQUENCE companies_id_seq CASCADE');
$this->addSql('ALTER TABLE comments DROP CONSTRAINT FK_5F9E962A4B89032C');
$this->addSql('ALTER TABLE posts DROP CONSTRAINT FK_885DBAFAA76ED395');
$this->addSql('ALTER TABLE users DROP CONSTRAINT FK_1483A5E9F5B7AF75');
$this->addSql('ALTER TABLE users DROP CONSTRAINT FK_1483A5E9979B1AD6');
$this->addSql('DROP TABLE addresses');
$this->addSql('DROP TABLE comments');
$this->addSql('DROP TABLE companies');
$this->addSql('DROP TABLE posts');
$this->addSql('DROP TABLE users');
$this->addSql('DROP TABLE messenger_messages');
}
}