2015-12-05 14:24:38 +01:00
|
|
|
<?php
|
|
|
|
namespace Framadate\Migration;
|
|
|
|
|
|
|
|
use Framadate\Utils;
|
2021-12-20 17:46:50 +01:00
|
|
|
use PDO;
|
2015-12-05 14:24:38 +01:00
|
|
|
|
|
|
|
class Increase_pollId_size implements Migration {
|
2021-12-20 17:46:50 +01:00
|
|
|
public function __construct() {
|
2015-12-05 14:24:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method should describe in english what is the purpose of the migration class.
|
|
|
|
*
|
|
|
|
* @return string The description of the migration class
|
|
|
|
*/
|
2021-12-20 17:46:50 +01:00
|
|
|
public function description(): string {
|
2015-12-05 14:24:38 +01:00
|
|
|
return 'Increase the size of id column in poll table';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method could check if the execute method should be called.
|
|
|
|
* It is called before the execute method.
|
|
|
|
*
|
2021-12-20 17:46:50 +01:00
|
|
|
* @param PDO $pdo The connection to database
|
2015-12-05 14:24:38 +01:00
|
|
|
* @return bool true if the Migration should be executed
|
|
|
|
*/
|
2021-12-20 17:46:50 +01:00
|
|
|
public function preCondition(PDO $pdo): bool {
|
2015-12-05 14:24:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This methode is called only one time in the migration page.
|
|
|
|
*
|
2021-12-20 17:46:50 +01:00
|
|
|
* @param PDO $pdo The connection to database
|
2015-12-05 14:24:38 +01:00
|
|
|
* @return bool true if the execution succeeded
|
|
|
|
*/
|
2021-12-20 17:46:50 +01:00
|
|
|
public function execute(PDO $pdo): bool {
|
2016-04-27 13:22:36 +02:00
|
|
|
$this->alterCommentTable($pdo);
|
2015-12-05 14:24:38 +01:00
|
|
|
$this->alterPollTable($pdo);
|
2016-04-27 13:22:36 +02:00
|
|
|
$this->alterSlotTable($pdo);
|
|
|
|
$this->alterVoteTable($pdo);
|
2021-12-20 17:46:50 +01:00
|
|
|
return true;
|
2016-04-27 13:22:36 +02:00
|
|
|
}
|
|
|
|
|
2021-12-20 17:46:50 +01:00
|
|
|
private function alterCommentTable(PDO $pdo): void
|
|
|
|
{
|
2016-04-27 13:22:36 +02:00
|
|
|
$pdo->exec('
|
|
|
|
ALTER TABLE `' . Utils::table('comment') . '`
|
|
|
|
CHANGE `poll_id` `poll_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
|
2015-12-05 14:24:38 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 17:46:50 +01:00
|
|
|
private function alterPollTable(PDO $pdo): void
|
|
|
|
{
|
2015-12-05 14:24:38 +01:00
|
|
|
$pdo->exec('
|
|
|
|
ALTER TABLE `' . Utils::table('poll') . '`
|
|
|
|
CHANGE `id` `id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
|
|
|
|
}
|
2016-04-27 13:22:36 +02:00
|
|
|
|
2021-12-20 17:46:50 +01:00
|
|
|
private function alterSlotTable(PDO $pdo): void
|
|
|
|
{
|
2016-04-27 13:22:36 +02:00
|
|
|
$pdo->exec('
|
|
|
|
ALTER TABLE `' . Utils::table('slot') . '`
|
|
|
|
CHANGE `poll_id` `poll_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
|
|
|
|
}
|
|
|
|
|
2021-12-20 17:46:50 +01:00
|
|
|
private function alterVoteTable(PDO $pdo): void
|
|
|
|
{
|
2016-04-27 13:22:36 +02:00
|
|
|
$pdo->exec('
|
|
|
|
ALTER TABLE `' . Utils::table('vote') . '`
|
|
|
|
CHANGE `poll_id` `poll_id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
|
|
|
|
}
|
2015-12-05 14:24:38 +01:00
|
|
|
}
|