aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.178_change_opengraph_data_pk.php
blob: d7154bdb206265092ea701f36ec410391ee3199a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/**
 * Add a numeric id column to table "opengraphdata" in order to avoid problems
 * with innodb and to reduce key size.
 *
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license GPL2 or any later version
 */
class ChangeOpengraphDataPk extends Migration
{
    public function up()
    {
        $query = "ALTER TABLE `opengraphdata`
                  DROP PRIMARY KEY,
                  ADD COLUMN `opengraph_id` INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST,
                  ADD UNIQUE KEY `url` (`url`(512))";
        DBManager::get()->exec($query);
    }

    public function down()
    {
        $query = "ALTER TABLE `opengraphdata`
                  DROP PRIMARY KEY,
                  DROP INDEX `url`,
                  DROP COLUMN `opengraph_id`,
                  ADD PRIMARY KEY (`url`)";
        DBManager::get()->exec($query);
    }
}