43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class AllowCompetitionWinnerRankTies extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
$db = \Config\Database::connect();
|
|
if (!$db->tableExists('competition_winners')) {
|
|
return;
|
|
}
|
|
|
|
if ($db->indexExists('competition_winners', 'competition_id_class_section_id_rank')) {
|
|
$db->query('DROP INDEX competition_id_class_section_id_rank ON competition_winners');
|
|
}
|
|
|
|
if (!$db->indexExists('competition_winners', 'competition_id_class_section_id_rank')) {
|
|
$db->query(
|
|
'CREATE INDEX competition_id_class_section_id_rank ON competition_winners (competition_id, class_section_id, rank)'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
$db = \Config\Database::connect();
|
|
if (!$db->tableExists('competition_winners')) {
|
|
return;
|
|
}
|
|
|
|
if ($db->indexExists('competition_winners', 'competition_id_class_section_id_rank')) {
|
|
$db->query('DROP INDEX competition_id_class_section_id_rank ON competition_winners');
|
|
}
|
|
|
|
$db->query(
|
|
'ALTER TABLE competition_winners ADD UNIQUE KEY competition_id_class_section_id_rank (competition_id, class_section_id, rank)'
|
|
);
|
|
}
|
|
}
|