janus/migrations/Version20201026161459.php

46 lines
2.8 KiB
PHP
Raw Normal View History

2020-10-26 17:16:29 +01:00
<?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 Version20201026161459 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create base entities';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE apikey (id INT AUTO_INCREMENT NOT NULL, consumer_id INT NOT NULL, token VARCHAR(255) NOT NULL, INDEX IDX_B84757A137FDBD6D (consumer_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE consumer (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE resource (id INT AUTO_INCREMENT NOT NULL, type_id INT NOT NULL, owner_id INT NOT NULL, INDEX IDX_BC91F416C54C8C93 (type_id), INDEX IDX_BC91F4167E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE resource_type (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, validation_schema LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE rule (id INT AUTO_INCREMENT NOT NULL, predicate VARCHAR(255) DEFAULT NULL, action VARCHAR(255) NOT NULL, name VARCHAR(255) DEFAULT NULL, type SMALLINT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE apikey ADD CONSTRAINT FK_B84757A137FDBD6D FOREIGN KEY (consumer_id) REFERENCES consumer (id)');
$this->addSql('ALTER TABLE resource ADD CONSTRAINT FK_BC91F416C54C8C93 FOREIGN KEY (type_id) REFERENCES resource_type (id)');
$this->addSql('ALTER TABLE resource ADD CONSTRAINT FK_BC91F4167E3C61F9 FOREIGN KEY (owner_id) REFERENCES consumer (id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE apikey DROP FOREIGN KEY FK_B84757A137FDBD6D');
$this->addSql('ALTER TABLE resource DROP FOREIGN KEY FK_BC91F4167E3C61F9');
$this->addSql('ALTER TABLE resource DROP FOREIGN KEY FK_BC91F416C54C8C93');
$this->addSql('DROP TABLE apikey');
$this->addSql('DROP TABLE consumer');
$this->addSql('DROP TABLE resource');
$this->addSql('DROP TABLE resource_type');
$this->addSql('DROP TABLE rule');
}
}