<?php

declare(strict_types=1);

namespace App\Migrations\Mysql;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200429093452 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '[Mysql] First init.';
    }

    public function up(Schema $schema): void
    {
        $this->skipIf(!$this->connection->getDatabasePlatform() instanceof MySQLPlatform, 'Mysql or Mariadb migration only. Skipped.');

        $this->addSql('CREATE TABLE koi_wishlist (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', parent_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, color VARCHAR(6) NOT NULL, image VARCHAR(255) DEFAULT NULL, seen_counter INT NOT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_98E338D2C53D045F (image), INDEX IDX_98E338D27E3C61F9 (owner_id), INDEX IDX_98E338D2727ACA70 (parent_id), INDEX idx_wishlist_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_user (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', username VARCHAR(32) NOT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, avatar VARCHAR(255) DEFAULT NULL, enabled TINYINT(1) NOT NULL, roles LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\', theme VARCHAR(255) NOT NULL, currency VARCHAR(3) NOT NULL, locale VARCHAR(5) NOT NULL, timezone VARCHAR(255) NOT NULL, date_format VARCHAR(255) NOT NULL, disk_space_allowed BIGINT DEFAULT 268435456 NOT NULL, visibility VARCHAR(255) NOT NULL, last_date_of_activity DATE DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_AC325055F85E0677 (username), UNIQUE INDEX UNIQ_AC325055E7927C74 (email), UNIQUE INDEX UNIQ_AC3250551677722F (avatar), INDEX idx_user_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_template (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_93620D607E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_log (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', type VARCHAR(255) DEFAULT NULL, logged_at DATETIME NOT NULL, object_id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', object_label VARCHAR(255) NOT NULL, object_class VARCHAR(255) NOT NULL, object_deleted TINYINT(1) DEFAULT \'0\' NOT NULL, payload LONGTEXT DEFAULT NULL, INDEX IDX_9A4DC1F17E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_loan (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', item_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', lent_to VARCHAR(255) NOT NULL, lent_at DATE NOT NULL, returned_at DATE DEFAULT NULL, INDEX IDX_E4728B1F126F525E (item_id), INDEX IDX_E4728B1F7E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_wish (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', wishlist_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, url LONGTEXT DEFAULT NULL, price VARCHAR(255) DEFAULT NULL, currency VARCHAR(6) DEFAULT NULL, comment LONGTEXT DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, image_small_thumbnail VARCHAR(255) DEFAULT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_F670F2D5C53D045F (image), UNIQUE INDEX UNIQ_F670F2D59F979BF1 (image_small_thumbnail), INDEX IDX_F670F2D5FB8E54CD (wishlist_id), INDEX IDX_F670F2D57E3C61F9 (owner_id), INDEX idx_wish_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_tag_category (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', label VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, color VARCHAR(7) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_DE4E5D497E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_inventory (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, content JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_882AFBE67E3C61F9 (owner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_field (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', template_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, position INT NOT NULL, type VARCHAR(255) NOT NULL, INDEX IDX_4FD5B8915DA0FB8 (template_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_photo (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', album_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', title VARCHAR(255) NOT NULL, comment LONGTEXT DEFAULT NULL, place VARCHAR(255) DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, image_small_thumbnail VARCHAR(255) DEFAULT NULL, taken_at DATETIME DEFAULT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_9779D1C53D045F (image), UNIQUE INDEX UNIQ_9779D19F979BF1 (image_small_thumbnail), INDEX IDX_9779D11137ABCF (album_id), INDEX IDX_9779D17E3C61F9 (owner_id), INDEX idx_photo_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_item (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', collection_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', template_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', name VARCHAR(255) NOT NULL, quantity INT NOT NULL, image VARCHAR(255) DEFAULT NULL, image_small_thumbnail VARCHAR(255) DEFAULT NULL, seen_counter INT NOT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_3EBAA302C53D045F (image), UNIQUE INDEX UNIQ_3EBAA3029F979BF1 (image_small_thumbnail), INDEX IDX_3EBAA302514956FD (collection_id), INDEX IDX_3EBAA3027E3C61F9 (owner_id), INDEX IDX_3EBAA3025DA0FB8 (template_id), INDEX idx_item_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_item_tag (item_id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', tag_id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', INDEX IDX_E09EDE52126F525E (item_id), INDEX IDX_E09EDE52BAD26311 (tag_id), PRIMARY KEY(item_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_collection (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', parent_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', title VARCHAR(255) NOT NULL, children_title VARCHAR(255) DEFAULT NULL, items_title VARCHAR(255) DEFAULT NULL, color VARCHAR(6) NOT NULL, image VARCHAR(255) DEFAULT NULL, seen_counter INT NOT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_7AA7B057C53D045F (image), INDEX IDX_7AA7B057727ACA70 (parent_id), INDEX IDX_7AA7B0577E3C61F9 (owner_id), INDEX idx_collection_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_album (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', parent_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', title VARCHAR(255) NOT NULL, color VARCHAR(6) NOT NULL, image VARCHAR(255) DEFAULT NULL, seen_counter INT NOT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_2DB8938AC53D045F (image), INDEX IDX_2DB8938A7E3C61F9 (owner_id), INDEX IDX_2DB8938A727ACA70 (parent_id), INDEX idx_album_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_tag (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', category_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', label VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, image_small_thumbnail VARCHAR(255) DEFAULT NULL, seen_counter INT NOT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_16FB1EB7C53D045F (image), UNIQUE INDEX UNIQ_16FB1EB79F979BF1 (image_small_thumbnail), INDEX IDX_16FB1EB77E3C61F9 (owner_id), INDEX IDX_16FB1EB712469DE2 (category_id), INDEX idx_tag_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('CREATE TABLE koi_datum (id CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', item_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', owner_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', type VARCHAR(255) NOT NULL, label VARCHAR(255) DEFAULT NULL, value LONGTEXT DEFAULT NULL, position INT DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, image_small_thumbnail VARCHAR(255) DEFAULT NULL, visibility VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_F991BE5C53D045F (image), UNIQUE INDEX UNIQ_F991BE59F979BF1 (image_small_thumbnail), INDEX IDX_F991BE5126F525E (item_id), INDEX IDX_F991BE57E3C61F9 (owner_id), INDEX idx_datum_visibility (visibility), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
        $this->addSql('ALTER TABLE koi_wishlist ADD CONSTRAINT FK_98E338D27E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_wishlist ADD CONSTRAINT FK_98E338D2727ACA70 FOREIGN KEY (parent_id) REFERENCES koi_wishlist (id)');
        $this->addSql('ALTER TABLE koi_template ADD CONSTRAINT FK_93620D607E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_log ADD CONSTRAINT FK_9A4DC1F17E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_loan ADD CONSTRAINT FK_E4728B1F126F525E FOREIGN KEY (item_id) REFERENCES koi_item (id)');
        $this->addSql('ALTER TABLE koi_loan ADD CONSTRAINT FK_E4728B1F7E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_wish ADD CONSTRAINT FK_F670F2D5FB8E54CD FOREIGN KEY (wishlist_id) REFERENCES koi_wishlist (id)');
        $this->addSql('ALTER TABLE koi_wish ADD CONSTRAINT FK_F670F2D57E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_tag_category ADD CONSTRAINT FK_DE4E5D497E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_inventory ADD CONSTRAINT FK_882AFBE67E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_field ADD CONSTRAINT FK_4FD5B8915DA0FB8 FOREIGN KEY (template_id) REFERENCES koi_template (id)');
        $this->addSql('ALTER TABLE koi_photo ADD CONSTRAINT FK_9779D11137ABCF FOREIGN KEY (album_id) REFERENCES koi_album (id)');
        $this->addSql('ALTER TABLE koi_photo ADD CONSTRAINT FK_9779D17E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_item ADD CONSTRAINT FK_3EBAA302514956FD FOREIGN KEY (collection_id) REFERENCES koi_collection (id)');
        $this->addSql('ALTER TABLE koi_item ADD CONSTRAINT FK_3EBAA3027E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_item ADD CONSTRAINT FK_3EBAA3025DA0FB8 FOREIGN KEY (template_id) REFERENCES koi_template (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE koi_item_tag ADD CONSTRAINT FK_E09EDE52126F525E FOREIGN KEY (item_id) REFERENCES koi_item (id)');
        $this->addSql('ALTER TABLE koi_item_tag ADD CONSTRAINT FK_E09EDE52BAD26311 FOREIGN KEY (tag_id) REFERENCES koi_tag (id)');
        $this->addSql('ALTER TABLE koi_collection ADD CONSTRAINT FK_7AA7B057727ACA70 FOREIGN KEY (parent_id) REFERENCES koi_collection (id)');
        $this->addSql('ALTER TABLE koi_collection ADD CONSTRAINT FK_7AA7B0577E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_album ADD CONSTRAINT FK_2DB8938A7E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_album ADD CONSTRAINT FK_2DB8938A727ACA70 FOREIGN KEY (parent_id) REFERENCES koi_album (id)');
        $this->addSql('ALTER TABLE koi_tag ADD CONSTRAINT FK_16FB1EB77E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
        $this->addSql('ALTER TABLE koi_tag ADD CONSTRAINT FK_16FB1EB712469DE2 FOREIGN KEY (category_id) REFERENCES koi_tag_category (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE koi_datum ADD CONSTRAINT FK_F991BE5126F525E FOREIGN KEY (item_id) REFERENCES koi_item (id)');
        $this->addSql('ALTER TABLE koi_datum ADD CONSTRAINT FK_F991BE57E3C61F9 FOREIGN KEY (owner_id) REFERENCES koi_user (id)');
    }

    public function down(Schema $schema): void
    {
        $this->skipIf(true, 'Always move forward.');
    }
}
