-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tec: Associate time spent with corresponding message
- Loading branch information
1 parent
4d0a5c7
commit c041744
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
// This file is part of Bileto. | ||
// Copyright 2022-2024 Probesys | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Platforms\MariaDBPlatform; | ||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
// phpcs:disable Generic.Files.LineLength | ||
final class Version20241119150300AddMessageToTimeSpent extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add the message_id column to the time_spent table.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$dbPlatform = $this->connection->getDatabasePlatform(); | ||
if ($dbPlatform instanceof PostgreSQLPlatform) { | ||
$this->addSql('ALTER TABLE time_spent ADD message_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE time_spent ADD CONSTRAINT FK_B417D625537A1329 FOREIGN KEY (message_id) REFERENCES message (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('CREATE INDEX IDX_B417D625537A1329 ON time_spent (message_id)'); | ||
} elseif ($dbPlatform instanceof MariaDBPlatform) { | ||
$this->addSql('ALTER TABLE time_spent ADD message_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE time_spent ADD CONSTRAINT FK_B417D625537A1329 FOREIGN KEY (message_id) REFERENCES message (id) ON DELETE SET NULL'); | ||
$this->addSql('CREATE INDEX IDX_B417D625537A1329 ON time_spent (message_id)'); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$dbPlatform = $this->connection->getDatabasePlatform(); | ||
if ($dbPlatform instanceof PostgreSQLPlatform) { | ||
$this->addSql('ALTER TABLE time_spent DROP CONSTRAINT FK_B417D625537A1329'); | ||
$this->addSql('DROP INDEX IDX_B417D625537A1329'); | ||
$this->addSql('ALTER TABLE time_spent DROP message_id'); | ||
} elseif ($dbPlatform instanceof MariaDBPlatform) { | ||
$this->addSql('ALTER TABLE time_spent DROP FOREIGN KEY FK_B417D625537A1329'); | ||
$this->addSql('DROP INDEX IDX_B417D625537A1329 ON time_spent'); | ||
$this->addSql('ALTER TABLE time_spent DROP message_id'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters