/usr/share/php/data/Horde_History/migration/3_horde_history_add_modseq.php is in php-horde-history 2.3.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 30 31 32 33 34 35 36 37 38 39 | <?php
class HordeHistoryAddModSeq extends Horde_Db_Migration_Base
{
public function up()
{
$t = $this->createTable('horde_histories_modseq', array('autoincrementKey' => false));
$t->column('history_modseq', 'integer', array('null' => false, 'default' => 0));
$t->column('history_modseqempty', 'integer', array('null' => false, 'default' => 0));
$t->end();
$this->addColumn('horde_histories', 'history_modseq', 'integer', array('default' => 0, 'null' => false));
$rows = $this->selectAll('SELECT history_id FROM horde_histories ORDER BY history_ts ASC');
$seq = 1;
$this->beginDbTransaction();
foreach ($rows as $row) {
$this->update(
'UPDATE horde_histories SET history_modseq = ? WHERE history_id = ?',
array($seq++, $row['history_id']));
}
if (!empty($rows)) {
$this->insert('INSERT INTO horde_histories_modseq (history_modseq) VALUES(?)', array($seq - 1));
}
$this->commitDbTransaction();
// Add the index after the new values are set for performance reasons.
$this->addIndex('horde_histories', array('history_modseq'));
// ...same with the autoincrement for this field.
$this->changeColumn('horde_histories_modseq', 'history_modseq', 'autoincrementKey');
}
public function down()
{
$this->dropTable('horde_histories_modseq');
$this->removeColumn('horde_histories', 'history_modseq');
}
}
|