|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DoctrineMigrations; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
|
9
|
|
|
use Ramsey\Uuid\Uuid; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Auto-generated Migration: Please modify to your needs! |
|
13
|
|
|
*/ |
|
14
|
|
|
final class Version20201229194545 extends AbstractMigration |
|
15
|
|
|
{ |
|
16
|
|
|
public function getDescription() : string |
|
17
|
|
|
{ |
|
18
|
|
|
return ''; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
private array $rooms = [ ]; |
|
22
|
|
|
|
|
23
|
|
|
public function preUp(Schema $schema): void { |
|
24
|
|
|
$stmt = $this->connection->executeQuery('SELECT * FROM room'); |
|
25
|
|
|
$this->rooms = $stmt->fetchAllAssociative(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function postUp(Schema $schema): void { |
|
29
|
|
|
$stmt = $this->connection->prepare('INSERT INTO resource_type (name, icon, uuid) VALUES (?, ?, ?)'); |
|
30
|
|
|
$stmt->bindValue(1, 'Raum', 'string'); |
|
31
|
|
|
$stmt->bindValue(2, 'fas fa-door-open', 'string'); |
|
32
|
|
|
$stmt->bindValue(3, Uuid::uuid4()->toString(), 'string'); |
|
33
|
|
|
$stmt->execute(); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$typeId = $this->connection->lastInsertId(); |
|
36
|
|
|
|
|
37
|
|
|
foreach($this->rooms as $room) { |
|
38
|
|
|
$stmt = $this->connection->prepare('INSERT INTO resource (id, type_id, name, description, is_reservation_enabled, uuid, class) VALUES (?, ?, ?, ?, ?, ?, ?)'); |
|
39
|
|
|
$stmt->bindValue(1, $room['id'], 'integer'); |
|
40
|
|
|
$stmt->bindValue(2, $typeId, 'integer'); |
|
41
|
|
|
$stmt->bindValue(3, $room['name'], 'string'); |
|
42
|
|
|
$stmt->bindValue(4, $room['description'], 'text'); |
|
43
|
|
|
$stmt->bindValue(5, $room['is_reservation_enabled'], 'boolean'); |
|
44
|
|
|
$stmt->bindValue(6, $room['uuid'], 'string'); |
|
45
|
|
|
$stmt->bindValue(7, 'room', 'string'); |
|
46
|
|
|
|
|
47
|
|
|
$stmt->execute(); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function up(Schema $schema) : void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->addSql('SET FOREIGN_KEY_CHECKS=0;'); |
|
54
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
|
55
|
|
|
$this->addSql('CREATE TABLE resource (id INT UNSIGNED AUTO_INCREMENT NOT NULL, type_id INT UNSIGNED DEFAULT NULL, name VARCHAR(16) NOT NULL, `description` LONGTEXT DEFAULT NULL, is_reservation_enabled TINYINT(1) NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', class VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BC91F4165E237E06 (name), INDEX IDX_BC91F416C54C8C93 (type_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); |
|
56
|
|
|
$this->addSql('CREATE TABLE resource_type (id INT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, icon VARCHAR(255) DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); |
|
57
|
|
|
$this->addSql('ALTER TABLE resource ADD CONSTRAINT FK_BC91F416C54C8C93 FOREIGN KEY (type_id) REFERENCES resource_type (id) ON DELETE SET NULL'); |
|
58
|
|
|
$this->addSql('DROP INDEX UNIQ_729F519B5E237E06 ON room'); |
|
59
|
|
|
$this->addSql('ALTER TABLE room DROP name, DROP description, DROP uuid, DROP is_reservation_enabled, CHANGE id id INT UNSIGNED NOT NULL'); |
|
60
|
|
|
$this->addSql('ALTER TABLE room ADD CONSTRAINT FK_729F519BBF396750 FOREIGN KEY (id) REFERENCES resource (id) ON DELETE CASCADE'); |
|
61
|
|
|
$this->addSql('SET FOREIGN_KEY_CHECKS=1;'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function down(Schema $schema) : void |
|
65
|
|
|
{ |
|
66
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
67
|
|
|
$this->addSql('ALTER TABLE room DROP FOREIGN KEY FK_729F519BBF396750'); |
|
68
|
|
|
$this->addSql('ALTER TABLE resource DROP FOREIGN KEY FK_BC91F416C54C8C93'); |
|
69
|
|
|
$this->addSql('DROP TABLE resource'); |
|
70
|
|
|
$this->addSql('DROP TABLE resource_type'); |
|
71
|
|
|
$this->addSql('ALTER TABLE room ADD name VARCHAR(16) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, ADD description LONGTEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, ADD uuid CHAR(36) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci` COMMENT \'(DC2Type:uuid)\', ADD is_reservation_enabled TINYINT(1) NOT NULL, CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL'); |
|
72
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_729F519B5E237E06 ON room (name)'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.