feat: multiple hotelcodes assignable to users

This commit is contained in:
Björn Fromme
2025-01-08 10:07:19 +01:00
parent 5a07d95837
commit c15188c43c
16 changed files with 256 additions and 67 deletions
+46
View File
@@ -0,0 +1,46 @@
<?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 Version20250107163840 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('ALTER TABLE user ADD hotel_codes JSON NOT NULL COMMENT \'(DC2Type:json)\'');
}
public function postUp(Schema $schema): void
{
$this->connection->executeQuery('UPDATE user SET hotel_codes="[]" WHERE hotel_code IS NULL');
$rows = $this->connection->fetchAllAssociative('SELECT id, hotel_code FROM user WHERE hotel_code IS NOT NULL');
foreach ($rows as $row) {
$this->connection->update('user', [
'hotel_codes' => json_encode([$row['hotel_code']]),
], [
'id' => $row['id'],
]);
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user DROP hotel_codes');
}
}